小编hid*_*hai的帖子

带有Hibernate Validator的Spring MVC.如何按组验证财产?

有两个问题:

1.Sping/MVC使用hibernate验证器,自定义验证器如何显示消息? 喜欢:使用Hibernate Validator进行交叉字段验证(JSR 303)

@FieldMatch.List({
    @FieldMatch(fieldName="password",verifyName="passwordVerify",message="password confirm valid!", groups={Default.class})
})
@ScriptAssert(lang="javascript",script="_this.name.equals(_this.verifyCode)")
public class LoginForm {...}
Run Code Online (Sandbox Code Playgroud)

如何在资源属性文件的jsp中显示消息?

NotEmpty.loginForm.name ="用户名不能为空!" NotEmpty.loginForm.password ="密码不能为空!"

2.我想将组验证器与spring mvc一起使用,就像一个userform用于登录和注册

    @FieldMatch.List({
    @FieldMatch(fieldName="password",verifyName="passwordVerify",message="password confirm valid!", groups={Default.class})
})@ScriptAssert(lang="javascript",script="_this.name.equals(_this.verifyCode)",groups={Default.class,LoginChecks.class,RegisterChecks.class})
public class LoginForm {
    @NotEmpty(groups={Default.class,LoginChecks.class,RegisterChecks.class})
    @Size(min=3,max=10,groups={LoginChecks.class,RegisterChecks.class})
    private String name;

    @NotEmpty(groups={Default.class,LoginChecks.class,RegisterChecks.class})
    @Size(max=16,min=5,groups={LoginChecks.class,RegisterChecks.class})
    private String password;

    private String passwordVerify;

    @Email(groups={Default.class,LoginChecks.class,RegisterChecks.class})
    private String email;

    private String emailVerify;
...
}
Run Code Online (Sandbox Code Playgroud)

控制器参数注释是@valid,任何注释支持组验证者按组?

第一篇文章:)

spring-mvc hibernate-validator bean-validation

8
推荐指数
1
解决办法
5104
查看次数