本文介绍了如何指定@Valid的验证组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在@Controller @RequestMapping方法中获得这样的参数:

  @ModelAttribute(myCandidate)@Valid Candidate myCandidate, 
BindingResult result

如何显式指定myCandidate的验证组?

解决方案

标准的java @Valid 注释不支持组。但是,Spring现在包括一个 @Validated 注释,它执行与 @Valid 相同的工作,但允许您指定

  @ModelAttribute(myCandidate)@Validated(UpdateGroup.class)Candidate myCandidate 



请注意,此注释仅适用于Spring 3.1及更高版本。


I get so parameters in @Controller @RequestMapping method:

@ModelAttribute("myCandidate") @Valid Candidate myCandidate,
BindingResult result

How can I explicit specify validation group for myCandidate ?

解决方案

The standard java @Valid annotation doesn't support groups. However, Spring now includes an @Validated annotation which does the same job as @Valid, but allows you to specify which groups to use in the validation:

@ModelAttribute("myCandidate") @Validated(UpdateGroup.class) Candidate myCandidate

Note that this annotation is only available in Spring 3.1 and newer.

这篇关于如何指定@Valid的验证组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 23:28