String a = "a"; ParamUtils.checkArgument(a.length()==2); returns throw IllegalArgumentException
String a = "a"; ParamUtils.checkArgument(a.length()==1);
注意:该方法与 ParamUtils.checkArgument(boolean, Object) 的区别是:该方法仅仅抛出异常。String a = "a";
ParamUtils.checkArgument(a.length()==2,"a的长度必须等于2");
returns throw IllegalArgumentException
注意:该方法与 ParamUtils.checkArgument(boolean) 的区别是:该方法在抛出异常的同时会返回自定义的错误信息。ParamUtils.checkArgument(boolean)也可以完成此功能Student student = null;
ParamUtils.checkNotNull(student);
returns throw NullPointerException
ParamUtils.checkArgument(boolean,Object)也可以完成此功能Student student = null;
ParamUtils.checkNotNull(student);
returns throw NullPointerException
ParamUtils.checkNotNull(Object, String, Object...)也可以完成此功能Student student = null;
ParamUtils.checkNotNull(student,"%s不能为空","学生信息");
returns throw NullPointerException
""StringUtils.emptyToNull("") return null
StringUtils.emptyToNull("abc") return "abc"
StringUtils.isBlank(null) // true
StringUtils.isBlank("") // true
StringUtils.isBlank("a") // false
注意:该方法与 StringUtils.isEmpty(String) 的区别是:
该方法会校验空白字符
null
例:
StringUtils.isEmpty(null) // true
StringUtils.isEmpty("") // false
StringUtils.isEmpty("a") // false
注意:该方法与 StringUtils.isBlank(String) 的区别是:该方法不校验空白字符。JsonUtils.jsonToList(String, Type)JsonUtils.jsonToList(String, Class)"null" StringUtils.nullToEmpty(null) return ""
StringUtils.nullToEmpty("abc") return "abc"
BigDecimalRandomUtils.randomString(String, int)
baseString为空null或者""则返回""
RandomUtils.randomString(String, int)}
ExcelUtils.read(new File("测试.xlsx"), Student1.class,1); returns List<Student1>
ExcelUtils.read(new File("测试.xlsx"), Student1.class,1); returns List<Student1>
" "public void download(HttpServletResponse response) throws IOException {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
ExcelUtils.write(response.getOutputStream(), DownloadData.class,data);
}
Copyright © 2021. All rights reserved.