Using Spring Validator outside of the context of Spring MVC

后端 未结 1 1939
无人及你
无人及你 2021-01-02 13:58

I\'ve used validators with backing objects and annotations in Spring MVC (@Validate). It worked well.

Now I\'m trying to understand exactly how it works with the Sp

相关标签:
1条回答
  • 2021-01-02 14:57

    Why don't you use the implementation that spring offers org.springframework.validation.MapBindingResult?

    You can do:

    Map<String, String> map = new HashMap<String, String>();
    MapBindingResult errors = new MapBindingResult(map, Shape.class.getName());
    
    ShapeValidator sv = new ShapeValidator();
    Shape shape = new Shape();
    sv.validate(shape, errors);
    
    System.out.println(errors);
    

    This will print out all that is in the error messages.

    Good luck

    0 讨论(0)
提交回复
热议问题