一、接收json参数,封装为Map
1.1、核心代码
/*** 接收json参数,封装为Map* @param servletRequest* @return* @throws Exception*/
@PostMapping("/getParam")
public R getParam(HttpServletRequest servletRequest) throws Exception {Map<String,Object> result = new ObjectMapper().readValue(servletRequest.getInputStream(), Map.class);log.info("MapController getParam result:{}", JSON.toJSONString(result));return R.ok().data(result);
}
1.2、Postman中传参
![](https://img-blog.csdnimg.cn/direct/d3fc50649d0d467c876d7bb4ef5eb4c0.png)
1.3、响应结果
![](https://img-blog.csdnimg.cn/direct/93e2287c2f9b4c3da9a6e3e2e19f8211.png)
1.4、后台日志记录
![](https://img-blog.csdnimg.cn/direct/0f65f093ca7b494e90a45f663bf2c2f8.png)
二、GET请求
2.1、接收GET请求方式的传参:第一种方式
2.1.1、核心代码
/*** 接收GET请求方式的传参:第一种方式** @param username 用户名* @param password 密码* @return*/
@GetMapping("/getParam1/{username}/{password}")
public R getParam1(@PathVariable String username, @PathVariable String password) {log.info("GETController getParam1 param username:{},password:{}", username, password);User8043VO user8043VO = new User8043VO(username, password);return R.ok().data(user8043VO);
}
2.1.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/b606d17f0d7a4ecd9238090af96357f3.png)
2.2、接收GET请求方式的传参:第二种方式
2.2.1、核心代码
/*** 接收GET请求方式的传参:第二种方式** @param username 用户名* @param password 密码* @return*/
@GetMapping("/getParam2")
public R getParam2(@RequestParam("username") String username,@RequestParam("password") String password) {log.info("GETController getParam2 param username:{},password:{}", username, password);User8043VO user8043VO = new User8043VO(username, password);return R.ok().data(user8043VO);
}
2.2.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/bcbc7b6cba8446af9190d5380a357e3b.png)
2.3、接收GET请求方式的传参:第三种方式
2.3.1、核心代码
/*** 接收GET请求方式的传参:第三种方式** @param id 编号* @param username 用户名* @param password 密码* @return*/
@GetMapping("/getParam3/{id}")
public R getParam3(@PathVariable Long id,@RequestParam("username") String username,@RequestParam("password") String password) {log.info("GETController getParam3 param id:{},username:{},password:{}", id, username, password);User8043VO user8043VO = new User8043VO(id, username, password);return R.ok().data(user8043VO);
}
2.3.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/fa4ea8d6d33a473081718b08927ed82f.png)
2.4、接收GET请求方式的传参:第四种方式
2.4.1、核心代码
/*** 接收GET请求方式的传参:第四种方式* @param request* @return*/
@GetMapping("/getParam4")
public R getParam4(HttpServletRequest request) {String id = request.getParameter("id");String username = request.getParameter("username");String password = request.getParameter("password");log.info("GETController getParam4 param id:{},username:{},password:{}", id, username, password);User8043VO user8043VO = new User8043VO(Long.parseLong(id), username, password);return R.ok().data(user8043VO);
}
2.4.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/1f3adce7fd8c4901a6999d283d7c6294.png)
三、POST请求
3.1、接收POST请求方式的传参:第一种方式
3.1.1、核心代码
/*** 接收POST请求方式的传参:第一种方式** @param username 用户名* @param password 密码* @return*/
@PostMapping("/postParam1/{username}/{password}")
public R postParam1(@PathVariable String username, @PathVariable String password) {log.info("POSTController postParam1 param username:{},password:{}", username, password);User8043VO user8043VO = new User8043VO(username, password);return R.ok().data(user8043VO);
}
3.1.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/03e562ef43974a47b467f1910eaeed35.png)
3.2、接收POST请求方式的传参:第二种方式
3.2.1、核心代码
/*** 接收POST请求方式的传参:第二种方式** @param username 用户名* @param password 密码* @return*/
@PostMapping("/postParam2")
public R postParam2(@RequestParam("username") String username,@RequestParam("password") String password) {log.info("POSTController postParam2 param username:{},password:{}", username, password);User8043VO user8043VO = new User8043VO(username, password);return R.ok().data(user8043VO);
}
3.2.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/0b73a82d4d524ceb95c437e486fec435.png)
![](https://img-blog.csdnimg.cn/direct/5b9378782113412691edcb135a7c775c.png)
3.3、接收POST请求方式的传参:第三种方式
3.3.1、核心代码
/*** 接收POST请求方式的传参:第三种方式** @param id 编号* @param username 用户名* @param password 密码* @return*/
@PostMapping("/postParam3/{id}")
public R postParam3(@PathVariable Long id,@RequestParam("username") String username,@RequestParam("password") String password) {log.info("POSTController postParam3 param id:{}, username:{},password:{}", id, username, password);User8043VO user8043VO = new User8043VO(id, username, password);return R.ok().data(user8043VO);
}
3.3.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/9bc41eca7c854b919b791026de765802.png)
![](https://img-blog.csdnimg.cn/direct/02e2b0abc71848b4b069534872a821ca.png)
3.4、接收POST请求方式的传参:第四种方式
3.4.1、核心代码
/*** 接收POST请求方式的传参:第四种方式** @param request* @return*/
@PostMapping("/postParam4")
public R postParam4(HttpServletRequest request) {String id = request.getParameter("id");String username = request.getParameter("username");String password = request.getParameter("password");log.info("POSTController postParam4 param id:{}, username:{},password:{}", id, username, password);User8043VO user8043VO = new User8043VO(Long.parseLong(id), username, password);return R.ok().data(user8043VO);
}
3.4.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/a9e015e275aa4bf8857e33bf2554656b.png)
![](https://img-blog.csdnimg.cn/direct/66f1e35a46f146f78d3d947b5b2be9a7.png)
3.5、接收POST请求方式的传参:第五种方式
3.5.1、核心代码
/*** 接收POST请求方式的传参:第五种方式** @param param* @return*/
@PostMapping("/postParam5")
public R postParam5(@RequestBody User8043VO param) {log.info("POSTController postParam5 param:{}", JSON.toJSONString(param));return R.ok().data(param);
}
3.5.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/56bf9587a954474b99beb816ad34ecd0.png)
3.6、接收POST请求方式的传参:第六种方式
3.6.1、核心代码
/*** 接收POST请求方式的传参:第六种方式** @param param* @return*/
@PostMapping("/postParam6")
public R postParam6(User8043VO param) {log.info("POSTController postParam6 param:{}", param);return R.ok().data(param);
}
3.6.2、Postman中传参 & 响应结果
![](https://img-blog.csdnimg.cn/direct/e2ea2c92d91a4f1e89360f218caa01bf.png)
![](https://img-blog.csdnimg.cn/direct/5caf7e84741245f2a132a6185887d1d0.png)