requestbody注解 requestbody和requestparam區(qū)別?
requestbody和requestparam區(qū)別?Requestbody處理httpentity傳遞的數(shù)據(jù),通常用于處理非內(nèi)容類(lèi)型的數(shù)據(jù):application/x-www-form-urlenc
requestbody和requestparam區(qū)別?
Requestbody
處理httpentity傳遞的數(shù)據(jù),通常用于處理非內(nèi)容類(lèi)型的數(shù)據(jù):application/x-www-form-urlencoded格式。
在get請(qǐng)求中,@requestbody不適用,因?yàn)闆](méi)有httpentity。
在post請(qǐng)求中,通過(guò)httpentity傳遞的參數(shù)必須在請(qǐng)求頭中聲明數(shù)據(jù)類(lèi)型content type。Spring MVC使用由
handleradapter配置的httpmessage轉(zhuǎn)換器解析httpentity中的數(shù)據(jù),然后將其綁定到相應(yīng)的bean。
Requestparam
request怎么獲得requestbody里的參數(shù)?
三個(gè)方法:[1請(qǐng)求.QueryString(“parameter”//獲取指定的參數(shù)并返回字符串
2request.QueryStrings請(qǐng)求.QueryStrings()//獲取所有參數(shù)并返回?cái)?shù)組
3request.setQuery查詢(“parameter”,“value of parameter”)//如果當(dāng)前地址欄中有此參數(shù),則會(huì)對(duì)其進(jìn)行更新。否則,將返回一個(gè)新的地址欄參數(shù)字符串。例如,當(dāng)前地址欄參數(shù)字符串是:?Name=A&site=neveronlinealert(request.setQuery查詢(“name”,“bluedestination”)如果地址欄參數(shù)中有“name”,那么?Name=bluedestination&;site=never返回 onlinesetquery方法具有自動(dòng)追加參數(shù)的功能。例如,當(dāng)前地址欄參數(shù)字符串是:?站點(diǎn)=從不在線提醒(request.setQuery查詢(“name”,“bluedestiny”)返回?Site=never同樣,如果地址欄中沒(méi)有參數(shù),參數(shù)警報(bào)將自動(dòng)添加(request.setQuery查詢(“name”,“bluedestiny”)返回?Name=bluedestiny<scriptlanguage=“JavaScript”><-->/作者:從不上網(wǎng):從不-在線.net