What does the @Valid annotation indicate in Spring?

前端 未结 8 1523
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 20:38

In the following example, the ScriptFile parameter is marked with an @Valid annotation.

What does @Valid annotation do?

<
8条回答
  •  -上瘾入骨i
    2020-12-04 21:18

    It's for validation purposes.

    Validation It is common to validate a model after binding user input to it. Spring 3 provides support for declarative validation with JSR-303. This support is enabled automatically if a JSR-303 provider, such as Hibernate Validator, is present on your classpath. When enabled, you can trigger validation simply by annotating a Controller method parameter with the @Valid annotation: After binding incoming POST parameters, the AppointmentForm will be validated; in this case, to verify the date field value is not null and occurs in the future.


    Look here for more info:
    http://blog.springsource.com/2009/11/17/spring-3-type-conversion-and-validation/

提交回复
热议问题