Java 带有注解的 Spring MVC 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/489703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:17:28  来源:igfitidea点击:

Spring MVC validation with Annotations

javaspringspring-mvcvalidation

提问by cdecker

I'm having quite some trouble since I migrated my controllers from classical inheritance to use the annotations like @Controller and @RequestMapping. The problem is that I don't know how to plug in validation like in the old case. Are there any good tutorials about this?

自从我将控制器从经典继承迁移到使用 @Controller 和 @RequestMapping 之类的注释以来,我遇到了很多麻烦。问题是我不知道如何像旧案例一样插入验证。有没有关于这方面的好教程?

采纳答案by yawmark

Have a look at §13.11.x of the Spring MVC documentation. It covers annotation-based controller configuration, including data binding. It should be very useful to you.

查看Spring MVC 文档的 §13.11.x。它涵盖了基于注释的控制器配置,包括数据绑定。它应该对你非常有用。

Good luck!

祝你好运!

回答by Mike Norrish

At a pinch, there's always this thing: http://annovalidator.sourceforge.net/- it's all tooled around using annotations for validation, and is designed to work with Spring.

在紧要关头,总是有这样的事情:http: //annovalidator.sourceforge.net/- 所有这些都是围绕使用注释进行验证而设计的,并且旨在与 Spring 一起使用。

回答by Mike Norrish

Spring 3 includes improved support for validation, and in particular, JSR-303 validation. You can validate form beans using the @Valid annotation and . See

Spring 3 包括对验证的改进支持,特别是 JSR-303 验证。您可以使用 @Valid 注释和 . 看

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#validation-beanvalidation

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#validation-beanvalidation

section 5.7.

第 5.7 节。