我正在开发Spring MVC应用程序,并且对Spring验证有疑问。首先,我在控制器中执行以下操作:
@RequestMapping(value = "/create", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody
Employee employeeCreate(@Valid @RequestBody EmployeeModelCreate objModel) throws Exception {
...
}
这是我的EmployeeModelCreate
课:
public class EmployeeModelCreate implements Serializable {
...
@NotBlank(message = "...")
private String password;
@NotBlank(message = "...")
private String confirmPassword;
...
//Setters and Getters
}
现在,我想对比较password
和进行验证confirmPassword
。此验证应检查这两个字段是否相等。我怎样才能做到这一点?任何帮助将不胜感激。
您可以创建一个自定义验证类,为此您需要实现Validator
接口,然后可以手动使用它,或使用@InitBinder
批注将其绑定到Spring MVC控制器。
该问题可能包含其他有用的信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句