本文整理汇总了Java中org.springframework.util.Assert.hasText方法的典型用法代码示例。如果您正苦于以下问题:Java Assert.hasText方法的具体用法?Java Assert.hasText怎么用?Java Assert.hasText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.Assert
的用法示例。
在下文中一共展示了Assert.hasText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public void delete(final String path) {
Assert.hasText(path, "Path must not be empty");
try {
sessionTemplate.delete(path);
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return;
}
throw VaultResponses.buildException(e, path);
}
}
示例2: removeCookie
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* 移除cookie
*
* @param request
* HttpServletRequest
* @param response
* HttpServletResponse
* @param name
* cookie名称
* @param path
* 路径
* @param domain
* 域
*/
public static void removeCookie(HttpServletRequest request, HttpServletResponse response, String name, String path,
String domain) {
Assert.notNull(request);
Assert.notNull(response);
Assert.hasText(name);
try {
name = URLEncoder.encode(name, "UTF-8");
Cookie cookie = new Cookie(name, null);
cookie.setMaxAge(0);
if (StringUtils.isNotEmpty(path)) {
cookie.setPath(path);
}
if (StringUtils.isNotEmpty(domain)) {
cookie.setDomain(domain);
}
response.addCookie(cookie);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例3: findField
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* <p>根据属性字段名称获取@{code java.lang.reflect.Field}</p>
*
* @param targetClass
* @param fieldName
* @return
*/
public static Field findField(Class<?> targetClass, String fieldName) {
Assert.notNull(targetClass, "Parameter 'targetClass' must be not null!");
Assert.hasText(fieldName, "Parameter 'fieldName' must be not empty!");
Class<?> searchType = targetClass;
while (!Object.class.equals(searchType) && searchType != null) {
Field[] fields = searchType.getDeclaredFields();
for (Field field : fields) {
if (fieldName.equals(field.getName())) {
return field;
}
}
searchType = searchType.getSuperclass();
}
return null;
}
示例4: getAccessibleField
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
* <p/>
* 如向上转型到Object仍无法找到, 返回null.
*
* @param targetClass 目标对象Class
* @param fieldName class中的字段名
* @return {@link java.lang.reflect.Field}
*/
public static Field getAccessibleField(final Class targetClass,
final String fieldName) {
Assert.notNull(targetClass, "targetClass不能为空");
Assert.hasText(fieldName, "fieldName不能为空");
for (Class<?> superClass = targetClass; superClass != Object.class; superClass = superClass
.getSuperclass()) {
try {
Field field = superClass.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
}
}
return null;
}
示例5: locateBundle
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Locates (through the {@link ArtifactLocator}) an OSGi bundle given as a
* String.
*
* The default implementation expects the argument to be in Comma Separated
* Values (CSV) format which indicates an artifact group, id, version and
* optionally the type.
*
* @param bundleId the bundle identifier in CSV format
* @return a resource pointing to the artifact location
*/
protected Resource locateBundle(String bundleId) {
Assert.hasText(bundleId, "bundleId should not be empty");
// parse the String
String[] artifactId = StringUtils.commaDelimitedListToStringArray(bundleId);
Assert.isTrue(artifactId.length >= 3, "the CSV string " + bundleId + " contains too few values");
// TODO: add a smarter mechanism which can handle 1 or 2 values CSVs
for (int i = 0; i < artifactId.length; i++) {
artifactId[i] = StringUtils.trimWhitespace(artifactId[i]);
}
ArtifactLocator aLocator = getLocator();
return (artifactId.length == 3 ? aLocator.locateArtifact(artifactId[0], artifactId[1], artifactId[2])
: aLocator.locateArtifact(artifactId[0], artifactId[1], artifactId[2], artifactId[3]));
}
示例6: setFieldValue
import org.springframework.util.Assert; //导入方法依赖的package包/类
public static void setFieldValue(Object object, String propertyName,
Object newValue, boolean targetAccessible)
throws NoSuchFieldException, IllegalAccessException {
Assert.notNull(object);
Assert.hasText(propertyName);
Field field = getDeclaredField(object, propertyName);
boolean accessible = field.isAccessible();
field.setAccessible(targetAccessible);
field.set(object, newValue);
field.setAccessible(accessible);
}
示例7: DefaultPublisherFactory
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Create {@link DefaultPublisherFactory} instance based on the provided {@link GcpProjectIdProvider}.
* <p>The {@link GcpProjectIdProvider} must not be null, neither provide an empty {@code projectId}.
* @param projectIdProvider provides the GCP project ID
*/
public DefaultPublisherFactory(GcpProjectIdProvider projectIdProvider) {
Assert.notNull(projectIdProvider, "The project ID provider can't be null.");
this.projectId = projectIdProvider.getProjectId();
Assert.hasText(this.projectId, "The project ID can't be null or empty.");
}
示例8: HandlerMethod
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Create an instance from a bean name, a method, and a {@code BeanFactory}.
* The method {@link #createWithResolvedBean()} may be used later to
* re-create the {@code HandlerMethod} with an initialized the bean.
*/
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
Assert.hasText(beanName, "Bean name is required");
Assert.notNull(beanFactory, "BeanFactory is required");
Assert.notNull(method, "Method is required");
Assert.isTrue(beanFactory.containsBean(beanName),
"BeanFactory [" + beanFactory + "] does not contain bean [" + beanName + "]");
this.bean = beanName;
this.beanFactory = beanFactory;
this.method = method;
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
this.parameters = initMethodParameters();
}
示例9: createQuery
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* 根据查询HQL与参数列表创建Query对象.
*
* @param values 命名参数,按名称绑定.
*/
public Query createQuery(final String queryString, final Map<String, ?> values) {
Assert.hasText(queryString, "queryString不能为空");
Query query = getSession().createQuery(queryString);
if (values != null) {
query.setProperties(values);
}
return query;
}
示例10: createSqlQueryMappingColumns
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Return a query using native SQL and column mapping.
*
* @param sql native SQL
* @param columnMapping column mapping,key is dbColumn, value is propertyName.
* @return the created Query using native SQL and column mapping config.
*/
public <T> Query<T> createSqlQueryMappingColumns(Class<T> entityType,
String sql,
Map<String, String> columnMapping) {
Assert.notNull(entityType, "entityType must not null");
Assert.hasText(sql, "sql must has text");
Assert.notEmpty(columnMapping, "columnMapping must not empty");
RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql);
columnMapping.entrySet().forEach(entry -> {
rawSqlBuilder.columnMapping(entry.getKey(), entry.getValue());
});
return ebeanServer.find(entityType).setRawSql(rawSqlBuilder.create());
}
示例11: setDatabaseType
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* @param databaseType the databaseType to set
*/
public void setDatabaseType(String databaseType) {
Assert.hasText(databaseType, "databaseType must not be empty nor null");
this.databaseType = databaseType;
}
示例12: setScript
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Set a fresh script String, overriding the previous script.
* @param script the script String
*/
public synchronized void setScript(String script) {
Assert.hasText(script, "Script must not be empty");
this.modified = !script.equals(this.script);
this.script = script;
}
示例13: Version
import org.springframework.util.Assert; //导入方法依赖的package包/类
@JsonCreator
public Version(@JsonProperty("build_number") String buildNumber) {
Assert.hasText(buildNumber, "Build Number must not be empty");
this.buildNumber = buildNumber;
}
示例14: isConnectable
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* @param host must not be {@literal null} or empty.
* @param port
* @return {@literal true} if the TCP port accepts a connection.
*/
public static boolean isConnectable(String host, int port) {
Assert.hasText(host, "Host must not be null or empty!");
try (Socket socket = new Socket()) {
socket.setSoLinger(true, 0);
socket.connect(new InetSocketAddress(host, port), (int) TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS));
return true;
} catch (Exception e) {
return false;
}
}
示例15: findHumanTask
import org.springframework.util.Assert; //导入方法依赖的package包/类
public HumanTaskDTO findHumanTask(String humanTaskId) {
Assert.hasText(humanTaskId, "humanTaskId不能为空");
TaskInfo taskInfo = taskInfoManager.get(Long.parseLong(humanTaskId));
return this.convertHumanTaskDto(taskInfo);
}