Spring Boot Post、Get接收 Map 参数
body application/json 模式
//POST @RequestBody Map map @RequestMapping(value = "/updat", method = RequestMethod.POST) public String updat(@RequestBody Mapmap) { System.out.println("map==>"+map); return String(map)); }
Get模式 aa=bb&cc=dd
//GET @RequestParam(required = false) Map map @GetMapping("/select") public String select( @RequestParam(required = false) Mapmap) { System.out.println("map==>"+map); return String(map)); }
application/x-www-form-urlencoded模式
前端contentType:application/x-www-form-urlencoded 1.public ResponseVo register(@RequestParam(value="username") String username) //或者直接用对象接收 2.public ResponseVo register(User user)
获取所有请求
//获取所有的请求参数 EnumerationparaNames=request.getParameterNames(); for(Enumeration e=paraNames;e.hasMoreElements();){ String thisName=e.nextElement().toString(); String thisValue=request.getParameter(thisName); System.out.println(“param的key:”+thisName+”————–param的value:”+thisValue); } //获取所有的头部参数 Enumeration headerNames=request.getHeaderNames(); for(Enumeration e=headerNames;e.hasMoreElements();){ String thisName=e.nextElement().toString(); String thisValue=request.getHeader(thisName); System.out.println(“header的key:”+thisName+”————–header的value:”+thisValue); }