Для переменной id
необходимо использовать аннотацию @ PathVariable , а для параметра name
- @RequestParam.
Вот полное рабочее решение:
@RestController
@RequestMapping("/user")
public class UserController {
@GetMapping("/{id}")
public String getUser(@PathVariable Long id, @RequestParam String name) {
System.out.println(" Got id by path param : " + id + " And Got name using Query Param " + name);
return " Got id by path param : " + id + " And Got name using Query Param " + name;
}
}
Подробнее см. здесь .
Теперь, когда вы делаете запрос
$ curl http://localhost:8085/user/30?name=abc
, вы получаете ответ:
Got id by path param : 30 And Got name using Query Param abc