一.jsonutil
1.JSONUtil.toJsonStr(a):
将a对象转化为json类型的字符串
2.JSONUtil.toBean(a,B.class):
eg:
Shop shop = JSONUtil.toBean(shopJson, Shop.class);
return shop;
将json类型的a字符串转换为对应的实体类B的对象。
二.StrUtil
1. StrUtil.isNotBlank:
判断是否存在,null、空字符串""、换行符均属于blank
2.StrUtil.join:
将集合中元素与给定元素拼接并返回
eg:List<Long> list=new ArrayList(Arrays.asList(1,2,3));
String strList=StrUtil.join(",",list) //strList={1,2,3}
三.BeanUtil
1.BeanUtil.copyProperties(a,aDTO.class)
将a中属性拷贝到aDTO并返回aDTO对象。
2.BeanUtil.beanToMap
Map<String,Object> amap=BeanUtil.beanToMap(aDTO)
将对象转换为HashMap存储。
3.BeanUtil.fillBeanWithMap(userMap,new userDTO(),false)
将Map转换为实体类,不忽略转换过程中的错误。
四.String
1.intern方法:返回字符串对象的规范表示,即返回字符串常量池中与该字符串相等的字符串的地址。(不管new多少字符串,值都相等。用户id的值一样,锁就一样)
五.@postconstruct
init(){
}:在初始化是执行
//校验手机号格式工具类
public class RegexUtils {
/**
* 是否是无效手机格式
* @param phone 要校验的手机号
* @return true:符合,false:不符合
*/
public static boolean isPhoneInvalid(String phone){
return mismatch(phone, RegexPatterns.PHONE_REGEX);
}
/**
* 是否是无效邮箱格式
* @param email 要校验的邮箱
* @return true:符合,false:不符合
*/
public static boolean isEmailInvalid(String email){
return mismatch(email, RegexPatterns.EMAIL_REGEX);
}
/**
* 是否是无效验证码格式
* @param code 要校验的验证码
* @return true:符合,false:不符合
*/
public static boolean isCodeInvalid(String code){
return mismatch(code, RegexPatterns.VERIFY_CODE_REGEX);
}
// 校验是否不符合正则格式
private static boolean mismatch(String str, String regex){
if (StrUtil.isBlank(str)) {
return true;
}
return !str.matches(regex);
}
}