How to get error text in controller from BindingResult

前端 未结 5 936
臣服心动
臣服心动 2020-12-01 01:58

I have an controller that returns JSON. It takes a form, which validates itself via spring annotations. I can get FieldError list from BindingResult, but they don\'t conta

5条回答
  •  日久生厌
    2020-12-01 02:54

    I met this problem recently, and found an easier way (maybe it's the support of Spring 3)

        List errors = bindingResult.getFieldErrors();
        for (FieldError error : errors ) {
            System.out.println (error.getObjectName() + " - " + error.getDefaultMessage());
        }
    

    There's no need to change/add the message source.

提交回复
热议问题