URL 的参数是最常用到的 Spring Boot 参数之一。
配置不同的 URL 能获取不同的数据。
/path/{variable 1}/{variable 2}/ ...
传递多个参数
一个路径参数
@RequestMapping("/path/{id}")
public String pathParam(@PathVariable Integer id) {
System.out.println(id);
return "Path Params is OK!!";
}
获取 URL 参数通过 @PathVariable 绑定形参 id 就能获取。
多个参数
两个
@RequestMapping("/path/{id}/{name}")
public String pathParam(@PathVariable Integer id,@PathVariable String name) {
System.out.println(id + " - " + name);
return "Path Params is OK!!";
}
再增加一个 「参数」即可。
请求参数的接收
参数中,@注解 + 参数类型 + 参数