@RequestParam,接收get或者post方式的前端参数。如果前端传递的参数和后端你接受的参数的字段名称是一致的可以省略不写,也可以直接写@RequestParam String id,如下面的接收前端传过来的id。这种情况参数不会拼接在URL上面。
@GetMapping("xxx/xxx")
public RequestResult get(
@ApiParam(name = "id", value = "主键", required = true) String id){}
@PathVariable,主要是用get方式接参,参数拼接在url后面。
@GetMapping("xxx/xxx/{id}")
public RequestResult get(
@ApiParam(name = "id", value = "主键", required = true) @PathVariable("id") String id) {}
@ApiParam只是用于生成swagger的文档注释参数而已。
本文详细解析了@RequestParam和@PathVariable注解在Java Spring框架中如何处理HTTP请求参数,包括GET和POST请求的区别,以及参数如何在URL中显示。
2000

被折叠的 条评论
为什么被折叠?



