在spring mvc的请求参数上是否可以使用Bean验证注释,如@Past
或@Length
?弹簧mvc控制器上的jsr-303注释参数
我想这样做:
@RequestMapping(method = RequestMethod.POST)
public RedirectView initiateSignup(@RequestParam @Valid @Past Date birthdate, BindingResult birthdateResult,
HttpServletResponse httpServletResponse) throws HttpMediaTypeNotAcceptableException {
我使用'@ Validated'注解工作。我知道创建一个模型类可以工作,但是我发现对于一个单独的属性有一点开销。 – Laures
酷,我没有见过@Validated之前。我阅读了你链接到的博客文章,看起来非常有用。感谢张贴的链接。 – sdouglass