为什么我不能用有效的参数与Spring MVC中RequestParam相处? [英] Why can't I use Valid parameter along with RequestParam in Spring MVC?
问题描述
例如:
公共字符串getStudentResult(@RequestParam(值=REGNO,要求= TRUE)字符串REGNO,ModelMap模型){
我如何使用@Valid这里的REGNO参数?
解决方案
@Valid可以用来验证豆类
该@Valid注释是标准的JSR-303 Bean验证API的一部分,而不是一个具体的弹簧结构。
Spring MVC的结合会如此,只要一个合适的验证已配置后验证@Valid对象。
块引用>参考:的http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html
Example:
public String getStudentResult(@RequestParam(value = "regNo", required = true) String regNo, ModelMap model){
How can I use @valid for the regNo parameter here?
解决方案@Valid can be used to validate beans. I have'nt seen it used on single string parameters. Also it requires a validator to be configured.
The @Valid annotation is part of the standard JSR-303 Bean Validation API, and is not a Spring-specific construct. Spring MVC will validate a @Valid object after binding so-long as an appropriate Validator has been configured.
Reference : http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html
这篇关于为什么我不能用有效的参数与Spring MVC中RequestParam相处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!