1、验证容器是否为空
CollectionUtils.isNotEmpty(iList)
2、String类型是否为空
StringUtils.isNotEmpty(rootSuit)
StringUtils.hasText(fromDate)
3、idString是否符合UUID的格式
CommonHelper.checkUuidPattern(rootSuit)
4、检验日期类型是否符合要求
public static boolean isValidDate(String str) {
boolean convertSuccess = true;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setLenient(false);
try {
format.parse(str);
} catch (java.text.ParseException e) {
throw new LifeCircleException(HttpStatus.INTERNAL_SERVER_ERROR,
LifeCircleErrorMessageMapper.DateFormatFail);
}
return convertSuccess;
}
5、对入参limit格式如(3,5)这样的校验,采用ParamCheckUtil.checkLimit(limit)
,也可以通过这个方式来获取limit的前一个参数和后一个参数
//limit校验
ParamCheckUtil.checkLimit(limit);
6、对includes变量的操作,对includes字符串按逗号进行分开
IncludesConstant.getValidIncludes(includes);
public static List<String> getValidIncludes(String includes){
if(StringUtils.isEmpty(includes)){
return new ArrayList<String>();
}
Set<String> set = new HashSet<String>(Arrays.asList(includes.split(",")));
List<String> includesList = getIncludesList();
for(String include : set){
if(!includesList.contains(include.trim())){
throw new LifeCircleException(HttpStatus.INTERNAL_SERVER_ERROR,
LifeCircleErrorMessageMapper.IncludesParamError.getCode(),
"includes中的:" + include + ",不在规定范围内");
}
}
return new ArrayList<String>(set);
}
7、对resType的方式,用IndexSourceType类来取
IndexSourceType.AssetType.getName();//取asstes的名字asstes