Spring : binding object with and without @ModelAttribute

后端 未结 7 1329
温柔的废话
温柔的废话 2020-12-30 05:47

I am new in Spring and registering a user.I did like this.

@RequestMapping(\"/register\")
    public String register(@ModelAttribute User user,BindingResult          


        
7条回答
  •  粉色の甜心
    2020-12-30 06:36

    Apart from adding object to Model, Spring MVC uses it to supply the bound object to a Controller method where you can use it, in your case to "register".

    And yes @ModelAtttribute is the safest and best way in Spring MVC to bind incoming post data to an object.

提交回复
热议问题