注释方式 | 解释说明 | server书写 | 参数接收 | 客户端请求 |
---|---|---|---|---|
@PathVariable | 直接读取请求路径中的参数;适合单个参数传递 | @GetMapping("/ceshi/{id}") | @PathVariable(name = “id”) String id | http://localhost:8080/ceshi/11 |
@RequestParam | 读取多个参数时使用;适合GET请求多个参数传递 | @GetMapping("/ceshi/{id}") | @RequestParam(name = “name”) String name;@RequestParam(name = “age”) String age | http://localhost:8080/ceshi/11?name=zhangsan&age=20 |
@RequestBody | 传输对象、json、map等;最适合POST请求 | @PostMapping(path = “/ceshi”) | @RequestBody User user;@RequestBody Map Map<String, Object> user;@RequestBody String str;(String可用于接收json,然后parseObject) | ![]() |
无注解 | 适用前端与后端传输对象一致时候 |
springboot中controller层几种不同传参方式对比
最新推荐文章于 2024-05-09 09:41:29 发布