为什么我不能用有效的参数与Spring MVC中RequestParam相处? [英] Why can't I use Valid parameter along with RequestParam in Spring MVC?

查看:484
本文介绍了为什么我不能用有效的参数与Spring MVC中RequestParam相处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

 公共字符串getStudentResult(@RequestParam(值=REGNO,要求= TRUE)字符串REGNO,ModelMap模型){

我如何使用@Valid这里的REGNO参数?


解决方案

@Valid可以用来验证豆类

。我have'nt看到它在单字符串参数使用。此外,它需要进行配置的验证。


  

该@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屋!

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