關(guān)于HttpServletRequest獲取POST請(qǐng)求Body參數(shù)的3種方式
HttpServletRequest獲取POST請(qǐng)求Body參數(shù)方式
第一種方式
request.getInputStream()
/** * If the parameter data was sent in the request body, such as occurs * with an HTTP POST request, then reading the body directly via * @see javax.servlet.ServletRequest#getInputStream or * @see javax.servlet.ServletRequest#getReader * @param request HttpServletRequest * @return String */ public static String getPostData(HttpServletRequest request) { StringBuilder data = new StringBuilder(); String line; BufferedReader reader; try { reader = request.getReader(); while (null != (line = reader.readLine())) { data.append(line); } } catch (IOException e) { return null; } return data.toString(); }
第二種方式
@RequestBody
@RequestMapping(value = "hello", method = {RequestMethod.POST}) @ResponseBody public String batchDisabledUsers(@RequestBody xxxDTO xx) { }
第三種方式
@RequestParam
@RequestMapping(value = "/testurl", method = RequestMethod.POST) @ResponseBody public StringTestUrl(@RequestParam("username")String username, @RequestParam("pwd")String pwd) { String txt = username + pwd; return txt; }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用@PropertySource讀取配置文件通過(guò)@Value進(jìn)行參數(shù)注入
這篇文章主要介紹了使用@PropertySource讀取配置文件通過(guò)@Value進(jìn)行參數(shù)注入,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03springsecurity記住我登錄時(shí)訪問(wèn)無(wú)權(quán)限接口跳轉(zhuǎn)登錄界面的處理方案
這篇文章主要介紹了springsecurity記住我登錄時(shí)訪問(wèn)無(wú)權(quán)限接口跳轉(zhuǎn)登錄界面的處理方案,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-02-02Java并發(fā)編程回環(huán)屏障CyclicBarrier
這篇文章主要介紹了Java并發(fā)編程回環(huán)屏障CyclicBarrier,文章繼續(xù)上文所介紹的Java并發(fā)編程同步器CountDownLatch展開(kāi)主題相關(guān)內(nèi)容,需要的小伙伴可以參考一下2022-04-04Arrays.sort如何實(shí)現(xiàn)降序排序
這篇文章主要介紹了Arrays.sort如何實(shí)現(xiàn)降序排序問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11SpringBoot整合redis實(shí)現(xiàn)輸入密碼錯(cuò)誤限制登錄功能
遇到這樣的需求需要實(shí)現(xiàn)一個(gè)登錄功能,并且2分鐘之內(nèi)只能輸入5次錯(cuò)誤密碼,若輸入五次之后還沒(méi)有輸入正確密碼,系統(tǒng)將會(huì)將該賬號(hào)鎖定1小時(shí),這篇文章主要介紹了SpringBoot整合redis并實(shí)現(xiàn)輸入密碼錯(cuò)誤限制登錄功能,需要的朋友可以參考下2024-02-02java并發(fā)高的情況下用ThreadLocalRandom來(lái)生成隨機(jī)數(shù)
如果我們想要生成一個(gè)隨機(jī)數(shù),通常會(huì)使用Random類。但是在并發(fā)情況下Random生成隨機(jī)數(shù)的性能并不是很理想,本文主要介紹了java并發(fā)高的情況下用ThreadLocalRandom來(lái)生成隨機(jī)數(shù),感興趣的可以了解一下2022-05-05