本文整理汇总了Java中org.springframework.util.StringUtils.split方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.split方法的具体用法?Java StringUtils.split怎么用?Java StringUtils.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.split方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toPredicate
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,
CriteriaBuilder builder) {
Path expression = null;
if(fieldName.contains(".")){
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
}else{
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
default:
return null;
}
}
示例2: parseSort
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private Sort parseSort() {
Sort retVal = null;
if (StringUtils.hasLength(this.sortFields)) {
if (this.sortFields.indexOf(",") > -1) {
String[] sorts = StringUtils.split(this.sortFields, ",");
if (sorts != null) {
for (String oneSortStr : sorts) {
Sort oneSort = parseOneSort(oneSortStr.trim());
if (oneSort == null) {
continue;
}
if (retVal == null) {
retVal = oneSort;
} else {
retVal = retVal.and(oneSort);
}
}
}
} else {
retVal = parseOneSort(this.sortFields.trim());
}
}
return retVal;
}
示例3: decodeSecretId
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public static String decodeSecretId(String authHeader) {
if (authHeader == null || authHeader.length() < HEADER_AUTH_PREFIX.length()) {
throw new IllegalArgumentException("Unrecognized Authorization header.");
}
String base64Final = authHeader.substring(HEADER_AUTH_PREFIX.length());
String usernameN64 = null;
try {
usernameN64 = new String(Base64.decodeBase64(base64Final.getBytes("UTF-8")));
}
catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Unrecognized Authorization header.");
}
String[] array = StringUtils.split(usernameN64, ":");
if (array == null || array.length != 2) {
throw new IllegalArgumentException("Unrecognized Authorization header.");
}
return array[0];
}
示例4: toPredicate
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
Path expression = null;
if (fieldName.contains(".")) {
System.out.println(root);
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
} else {
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case RLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
case ISNULL:
return builder.isNull(expression);
case NOTNULL:
return builder.isNotNull(expression);
default:
return null;
}
}
示例5: fromRequest
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Prepare a builder by copying the scheme, host, port, path, and
* query string of an HttpServletRequest.
* @param request to build path from
* @return a URI component builder
*/
public static YourServletUriComponentsBuilder fromRequest(HttpServletRequest request) {
String scheme = request.getScheme();
String host = request.getServerName();
int port = request.getServerPort();
String hostHeader = request.getHeader("X-Forwarded-Host");
if (StringUtils.hasText(hostHeader)) {
String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader);
String hostToUse = hosts[0];
if (hostToUse.contains(":")) {
String[] hostAndPort = StringUtils.split(hostToUse, ":");
host = hostAndPort[0];
port = Integer.parseInt(hostAndPort[1]);
}
else {
host = hostToUse;
port = -1;
}
}
String portHeader = request.getHeader("X-Forwarded-Port");
if (StringUtils.hasText(portHeader)) {
port = Integer.parseInt(portHeader);
}
String protocolHeader = request.getHeader("X-Forwarded-Proto");
if (StringUtils.hasText(protocolHeader)) {
scheme = protocolHeader;
}
YourServletUriComponentsBuilder builder = new YourServletUriComponentsBuilder();
builder.scheme(scheme);
builder.host(host);
if (scheme.equals("http") && port != 80 || scheme.equals("https") && port != 443) {
builder.port(port);
}
builder.pathFromRequest(request);
builder.query(request.getQueryString());
return builder;
}
示例6: matchExtenderVersionRange
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) {
Assert.notNull(bundle);
// get version range
String range = (String) bundle.getHeaders().get(header);
boolean trace = log.isTraceEnabled();
// empty value = empty version = *
if (!StringUtils.hasText(range))
return true;
if (trace)
log.trace("discovered " + header + " header w/ value=" + range);
// do we have a range or not ?
range = StringUtils.trimWhitespace(range);
// a range means one comma
int commaNr = StringUtils.countOccurrencesOf(range, COMMA);
// no comma, no intervals
if (commaNr == 0) {
Version version = Version.parseVersion(range);
return versionToMatch.equals(version);
}
if (commaNr == 1) {
// sanity check
if (!((range.startsWith(LEFT_CLOSED_INTERVAL) || range.startsWith(LEFT_OPEN_INTERVAL)) && (range.endsWith(RIGHT_CLOSED_INTERVAL) || range.endsWith(RIGHT_OPEN_INTERVAL)))) {
throw new IllegalArgumentException("range [" + range + "] is invalid");
}
boolean equalMin = range.startsWith(LEFT_CLOSED_INTERVAL);
boolean equalMax = range.endsWith(RIGHT_CLOSED_INTERVAL);
// remove interval brackets
range = range.substring(1, range.length() - 1);
// split the remaining string in two pieces
String[] pieces = StringUtils.split(range, COMMA);
if (trace)
log.trace("discovered low/high versions : " + ObjectUtils.nullSafeToString(pieces));
Version minVer = Version.parseVersion(pieces[0]);
Version maxVer = Version.parseVersion(pieces[1]);
if (trace)
log.trace("comparing version " + versionToMatch + " w/ min=" + minVer + " and max=" + maxVer);
boolean result = true;
int compareMin = versionToMatch.compareTo(minVer);
if (equalMin)
result = (result && (compareMin >= 0));
else
result = (result && (compareMin > 0));
int compareMax = versionToMatch.compareTo(maxVer);
if (equalMax)
result = (result && (compareMax <= 0));
else
result = (result && (compareMax < 0));
return result;
}
// more then one comma means incorrect range
throw new IllegalArgumentException("range [" + range + "] is invalid");
}
示例7: init
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@PostConstruct
public void init() {
this.excludeArr = StringUtils.split(exclude, ",");
}