Thymeleaf not displaying Spring form error messages

前端 未结 3 1888
北荒
北荒 2020-12-14 06:55

I\'m migrating a Spring jsp application to Thymeleaf but having problems displaying form errors.

I\'m using the SpringTemplateEngine and ThymeleafViewResolver and re

3条回答
  •  感动是毒
    2020-12-14 07:20

    I think you may be having the same issue as I did - please see :

    • Fields object functions (Spring)

    There it is answered by Daniel Fernandez. Basically your form object th:object="${form}" is named "form" but your controller is looking for "customerForm" (class name) not "form" (the variable name)

    can be renamed with @ModelAttribute("data")

    copied from that link use:

    public String post(@Valid FormData formData, BindingResult result, Model model){
        // th:object="${formData}"
    }
    

    or

    public String post(@Valid @ModelAttribute("data") FormData data, BindingResult result, Model model){
        // th:object="${data}"
    } 
    

提交回复
热议问题