春天:@ModelAttribute VS @RequestBody [英] Spring: @ModelAttribute VS @RequestBody
本文介绍了春天:@ModelAttribute VS @RequestBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我错了,请纠正我.两者均可用于数据绑定.
Please correct me if I am wrong. Both can be used for Data Binding.
问题是什么时候使用@ModelAttribute?
The question is when to use @ModelAttribute?
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
public String processSubmit(@ModelAttribute Pet pet) { }
另外,什么时候使用@RequestBody?
In addition, when to use @RequestBody?
@RequestMapping(value = "/user/savecontact", method = RequestMethod.POST
public String saveContact(@RequestBody Contact contact){ }
根据我的理解,两者都有类似的目的.
According to my understanding both serves the similar purpose.
谢谢!!
推荐答案
据我所知,最简单的方法是,@ModelAttribute
将接受一个查询字符串.所以,所有的数据都是通过url传递给服务器的.
The simplest way for my understanding is, the @ModelAttribute
will take a query string. so, all the data are being pass to the server through the url.
对于@RequestBody
,所有的数据都会通过一个完整的JSON body传递给服务器.
As for @RequestBody
, all the data will be pass to the server through a full JSON body.
这篇关于春天:@ModelAttribute VS @RequestBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文