How to specify validation group for @Valid?

后端 未结 1 849
暖寄归人
暖寄归人 2020-12-13 13:24

I get so parameters in @Controller @RequestMapping method:

@ModelAttribute(\"myCandidate\") @Valid Candidate myCandidate,
BindingResult result
相关标签:
1条回答
  • 2020-12-13 13:47

    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.

    0 讨论(0)
提交回复
热议问题