发表于: 2019-08-28 22:22:42
1 666
今天完成的事情:自定义注解整合国际化资源,原来hibernate包里面有加载国际化资源的方法,只不过加载的名字是固定的资源文件名固定位ValidationMessages.properties
然后写了测试类测试参数校验结果
public static <T> void errorMessage(T t) {
if(null==t){
System.out.println("数据为空");
}Set<ConstraintViolation<T>> set = validator.validate(t);
for (ConstraintViolation<T> constraintViolation : set) {
System.out.println(constraintViolation.getMessage());
}
}
public static void main(String[]args){
Student student=new Student();
student.setIntroduce("610893080");
errorMessage(student);
}
这里采用泛型方法,这样参数校验就变成了一个可以接收任意数据类型做参数校验的工具类
@CheckValue(field = "phone",message="{phone.code.error}")
private String introduce;
phone.code.error={field}\u683c\u5f0f\u4e0d\u6b63\u786e
properties文件中的内容采用的是unicode编码格式,也可以在idea中设置,直接写中文.
明天计划的事情:继续任务七.
遇到的问题:暂无
收获:学会了validation和国际化资源的整合.
评论