1.SSM框架的,如下示例解析
1 @ResponseBody 2 @RequestMapping(value = "/PostInfo") 3 public void enter(@RequestBody Map map) throws Exception { 4 JSONObject jsonToMap = JSONObject.fromObject(map); // map转json 5 System.out.println("Enter--请求转json:" + jsonToMap); 6 KeTuoRe kt = (KeTuoRe) JSONObject.toBean(decode, KeTuoRe.class);// 转Bean 7 // ...拿到转化数据进行业务处理 8 }
body--raw,参数传输使用json字符串。我的请求用的是加密数据,示例代码里删去了解码这部分。测试可以用自己的json字符串整合业务。
2.springboot框架下,如下示例
@PostMapping(value = “/test”) public JSONObject Test(InputStream inputStream) { JSONObject json=new JSONObject(); String result = “”; try { ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = inputStream.read(buffer)) != -1) { outSteam.write(buffer, 0, len); } outSteam.close(); inputStream.close(); result = new String(outSteam.toByteArray(), "UTF-8");//得到数据 result = org.apache.commons.lang3.StringEscapeUtils.unescapeJava(result);//去转义符 斜杠 //String newStr = result.substring(1, result.length()-1);//去除头和尾引号 } catch (Exception e) { e.printStackTrace(); } json.put(“result”, result); return json; }
postman请求格式如上,请求的json字符串内容可以自己拼接一下。后台拿到数据后可加上自己业务就行。