「Spring」@PathVariableアノテーションのサンプル
説明
メソッドパラメーターを URI テンプレート変数にバインドする必要があることを示すアノテーション。
使用例1
@GetMapping("/students/{studentId}/users/{userId}")
public User searchUser(@PathVariable Long studentId, @PathVariable Long userId) {
// some code
}
使用例2
@Controller
@RequestMapping("/students/{studentId}")
public class studentController {
@GetMapping("/users/{userId}")
public User searchUsert(@PathVariable Long studentId, @PathVariable Long userId) {
// some code
}
}
使用例3
@GetMapping("/emp/{name}")
public String emp(@PathVariable("name") String name) {
// some code
}
使用例4
@GetMapping("/emp/{age}")
public String emp(@PathVariable("age") Integer age) {
// some code
}