1. 字段截取 。
// 字符截取
String str = null;
// 有不为空判断
String[] item = StringUtils.splitByWholeSeparatorPreserveAllTokens(str,",");
// 没有为空判断,会抛异常
String[] item2 = str.split(",");
2. 参数校验(使用在实体类中),要在控制器类要使用的方法中加入@Validated,参数校验才会起作用。
// 非空验证
@NotBlank(message = "xxx不能为空")
public int xxx = 10;
更多看@Validated注解详解,分组校验,嵌套校验,@Valid和@Validated 区别,Spring Boot @Validated_昌杰的攻城狮之路的博客-CSDN博客_@validated注解
3. 对象的拷贝。
BeanUtils.copyProperties("源","目标");
4.判断值是否相同(忽略大小写)、判断字符串是否包含。
String str2 = "GET";
// 忽略大小写进行判断是否相同
if (StringUtils.equalsIgnoreCase("get", str2)) {
// 判断str2是否有G
boolean contains = StringUtils.contains(str2, "G");
}
5.判断集合
List<String> strings = new ArrayList<>();
if(CollectionUtils.isEmpty(strings)){
}