如何为@Valid 指定验证组? [英] How to specify validation group for @Valid?

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

问题描述

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

I get so parameters in @Controller @RequestMapping method:

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

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

How can I explicit specify validation group for myCandidate ?

推荐答案

标准的 java @Valid 注释不支持组.但是,Spring 现在包含一个 @Validated 注释,它与 @Valid 的工作相同,但允许您指定在验证中使用哪些组:

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

请注意,此注解仅在 Spring 3.1 及更新版本中可用.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆