Spring : binding object with and without @ModelAttribute

后端 未结 7 1298
温柔的废话
温柔的废话 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:54

    Looking at current (Spring 5.1.5) documentation (https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-arguments):

    Controller method argument - Any other argument [GP - without annotation]:

    If a method argument is not matched to any of the earlier values in this table and
    it is a simple type (as determined by BeanUtils#isSimpleProperty),
    it is a resolved as a @RequestParam. Otherwise, it is resolved as a @ModelAttribute.
    

    So if you have a non simple property as parameter in a controller mapped method, it's the exact equivalent of annotating it as @ModelAttribute.

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