我即将在Spring 3.1
. 我正在使用注释来验证我的模型,如下所示:
模型:
@Column(name = "mailAddress", nullable = false)
@Email
private String mailAddress;
@Column(name = "school", nullable = false)
@NotBlank
@Size(min = 3, max = 100)
private String school;
控制器:
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addBooking(
@ModelAttribute("new-booking") @Valid Booking booking,
BindingResult result, Map<String, Object> model) {
if (result.hasErrors()) {
return "booking";
}
return "success";
}
问题是,它验证了school
但不是mailAddress
. 如果您输入一个空的mailAddress
,它将接受它。