完整代码在github: https ://github.com/cuipengfei/MPJSP/tree/master/tmp
在控制器中,有一个处理提交的方法:
@RequestMapping(value = "/home", method = RequestMethod.POST)
public void handleSubmit(Customer model, BindingResult result) {
System.out.println(model.getUserName());
result.rejectValue("userName", "required.userName", "user name invalid");
}
而在jsp中,有这样一种形式:
<form:form method="POST" action="home" modelAttribute="Customer">
<table>
<tr>
<td>Username :</td>
<td><form:input path="userName" /></td>
<td><form:errors path="userName" cssClass="error" /></td>
</tr>
<tr>
<td colspan="3"><input type="submit" /></td>
</tr>
</table>
</form:form>
控制器每次都拒绝值,但不显示错误消息。
完整代码可以在这里找到: https ://github.com/cuipengfei/MPJSP/tree/master/tmp