Spring: @ModelAttribute VS @RequestBody

后端 未结 7 498
闹比i
闹比i 2020-12-04 16:19

Please correct me if I am wrong. Both can be used for Data Binding.

The question is when to use @ModelAttribute?

@RequestMapping(val         


        
7条回答
  •  感动是毒
    2020-12-04 16:52

    With @ModelAttribute, you pass data in URL params and with @RequestBody you pass it as JSON body. If you're making a REST API then it's better to use @RequestBody. Over most youtube tutorials you might find use of @ModelAttribute - That's simply because they might be demonstrating concepts regarding Spring MVC and are using URL's to pass data.

提交回复
热议问题