How to: Spring get rid of @Validate for automatic Controller validation?

后端 未结 3 1694
自闭症患者
自闭症患者 2021-02-09 13:39

I know about @Valid annotation to instruct spring to validate for example a Controller argument according to JSR-303 in such this example:

@GetMappi         


        
3条回答
  •  半阙折子戏
    2021-02-09 14:15

    unfortunately there is no "legal" way to do it.

    Furthermore @Valid is not enough. You need also a BindingResult method parameter to be able to check the validation result: bindingResult.hasErrors()

    If you don't want to use BindingResult, you could write your own Validator and throw an Exception in case of invalid input.

提交回复
热议问题