通常狀況下,web應用中,瀏覽器發送http請求,傳參數的時候都是做爲param傳遞的,java服務端經過request.getParameter(name)
能夠獲取參數內容;java
可是會有一些場景,把參數放在了http的payload中(contentType:」application/json」),這時,使用getParameter就獲取不到了, 好比下面這張圖,參數是json字符串,放在了payload中
實際上,payload,就是http的body,經過讀取body,就獲取到了web
http body經過讀取input流能夠獲得spring
br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8")); StringBuffer sb = new StringBuffer(""); String temp; while ((temp = br.readLine()) != null) { sb.append(temp); } br.close(); params = sb.toString();
若是傳遞的是json,獲得字符串以後,再反序列化成json對象就能夠了json
SpringMVC中有一個@RequestBody
註解,就是用來將請求body中的json轉換爲java對象的,不只轉換普通的java bean,也能夠是List,很方便瀏覽器
@RequestMapping(value = "/query", method = RequestMethod.POST) public ModelAndView queryList(@ModelAttribute("ReportBo") ReportBo query, @RequestBody ReportBo query1, HttpServletRequest request) { }
參考文檔mvc
http://blog.csdn.net/giraffe_zj/article/details/3343143
http://www.oschina.net/question/227902_162591
http://blog.csdn.net/wfung_kwok/article/details/7042101
app