Best practices for validation depending on actions Spring MVC

前端 未结 2 1316
谎友^
谎友^ 2021-02-05 19:37

I am trying to perform validation using Spring validation. I am wondering what is the best practice to perform validation that depends mainly on user\'s action, hereafter, I hav

2条回答
  •  我在风中等你
    2021-02-05 20:15

    Depends that you want to do it. All solutions are good if you apply in all of your validators the same and you want to validate some business logic, not only if it's null or not (for this purpose you can use the @Valid annotation and annotation @Not null in your objects).

    For me, if I have an object Foo I only want one Validator for this object, and then I have several methods for validate the data depends of I need in my controllers, for example, one for saving new Foo or other one for validating before updating, etc...

提交回复
热议问题