@PathVariable不推荐使用,仅在单个参数的时候选择使用
@GetMapping("/getId/{id}")
@ResponseBody
public String pathVariableTest(@PathVariable Integer id) {
return "id: " + id;
}
推荐使用,适用于单个、多个参数的情况
@GetMapping("/getId/{id}")
@ResponseBody
public String pathVariableTest(@PathVariable("id") Integer id) {
return "id: " + id;
}
@GetMapping("/getIdAny/{id}/{name}")
@ResponseBody
public String pathVariableTestAny(@PathVariable("id") Integer id, @PathVariable("name") String name) {
return "id:" + id + "name:" + name;
}
@GetMapping("/getId/{idValue}")
@ResponseBody
public String pathVariableTest(@PathVariable("idValue") Integer id) {
return "id: " + id;
}
以上三种方式的调用结果都是成功的

@RequestParam@RequestParam:将请求参数绑定到你控制器的方法参数上,是 SpringMVC 中接收普通参数的注解
@RequestParam(value = "参数名", required = "true", defaultValue= " ")
value 或 name :参数名required:是否包含该参数,默认为 true,表示该请求路径中必须包含该参数,如果不包含就报错defaultValue:默认参数值,如果设置了该值,required = true 将失效,自动为 false,如果没有传该参数,就使用默认值不推荐使用,仅在单个参数的时候选择使用
@GetMapping("/getId")
@ResponseBody
public