requestparam注解用法 requestbody和requestparam區(qū)別?
requestbody和requestparam區(qū)別?Requestbody處理httpentity傳遞的數(shù)據(jù),通常用于處理非內(nèi)容類型的數(shù)據(jù):application/x-www-form-urlenc
requestbody和requestparam區(qū)別?
Requestbody
處理httpentity傳遞的數(shù)據(jù),通常用于處理非內(nèi)容類型的數(shù)據(jù):application/x-www-form-urlencoded格式。
在get請(qǐng)求中,@requestbody不適用,因?yàn)闆]有httpentity。
在post請(qǐng)求中,通過httpentity傳遞的參數(shù)必須在請(qǐng)求頭中聲明數(shù)據(jù)類型content type。Spring MVC使用由
handleradapter配置的httpmessage轉(zhuǎn)換器解析httpentity中的數(shù)據(jù),然后將其綁定到相應(yīng)的bean。
Requestparam
用于處理內(nèi)容類型:content encoded for application/x-www-form-urlencoded。(在HTTP協(xié)議中,如果未指定內(nèi)容類型,則傳遞的默認(rèn)參數(shù)是application/x-www-form-urlencoded type)
@RequestParam和@RequestBody的區(qū)別?
最近,我們還遇到了這個(gè)問題,因?yàn)楸韱伪旧聿恢С謕ut方法。
解決方案:
1:使用@requestbody而不是@requestparam
2:不要使用表單發(fā)送參數(shù)
~]@requestmapping(value=“/list”,方法=請(qǐng)求方法.GET)
public String getAll(Model){
Set<GroupSecure> secures=快去拿()
模型.addAttribute(“secures”,secures)
return“group/list”
}
@RequestMapping(value=“/list”,method=請(qǐng)求方法.GET,params=“method=one”)
公共字符串getOneUser(@RequestParam(value=“name”)字符串名,Model Model){
Set<GroupSecure> secures=redisDao.getByName(姓名)模型.addAttribute(“secures”,secures)
return“group/list”
}