【发布时间】:2011-08-29 14:47:26
【问题描述】:
我在 spring 中遇到了一个使用 hibenate 验证器进行验证的简单表单的问题 我的表格:
<form:form method="POST" commandName="info">
username:<form:input path="username"/> <form:errors path="username"></form:errors>
password:<form:password path="password"/><form:errors path="password"></form:errors>
<input type="submit" value="add new writer">
</form:form>
我的表单控制器:
@RequestMapping(method=RequestMethod.POST,value={"/createnewuser"})
public String showCreateNewUserFrom( @javax.validation.Valid Information info,Model model,BindingResult br)
{
//System.out.println("hello post");
if(br.hasErrors())
{
return "admin/createuserform";
}
else
return "admin/createuserform";
}
我的问题是当我的表单无效时抛出异常!!我想要错误的 jsp 视图
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'information' on field 'username': rejected value [vc]; codes [Size.information.username,Size.username,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.username,username]; arguments []; default message [username],10,4]; default message [username must be at least 4 and at most 10 character]
Field error in object 'information' on field 'password': rejected value [fg]; codes [Size.information.password,Size.password,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.password,password]; arguments []; default message [password],8,5]; default message [username must be at least 5 and at most 8 character]
任何帮助我都会非常高兴
【问题讨论】:
标签: hibernate spring-mvc hibernate-validator