Rest API 混合使用 Path Param 和 RequestParam
Rest API with mix of Path Param and RequestParam
有人要求我构建一个混合了路径参数和请求参数的 Rest 端点,看起来像 -
/user/{user}?refresh={refresh}
请求参数应该是可选的。
我试过 String getUser(@PathVariable String user, @RequestParam Map<String, String> params);
但它使 RequestParam 成为强制性的(如它在 Swagger UI 中所示)。
我怎样才能让它成为可选的?
设置required
to false
in the @RequestParam
注解,如下:
@GetMapping("/user/{user}?refresh={refresh}")
String getUser(@PathVariable String user, @RequestParam(required = false) String refresh) {
...
}
有人要求我构建一个混合了路径参数和请求参数的 Rest 端点,看起来像 -
/user/{user}?refresh={refresh}
请求参数应该是可选的。
我试过 String getUser(@PathVariable String user, @RequestParam Map<String, String> params);
但它使 RequestParam 成为强制性的(如它在 Swagger UI 中所示)。
我怎样才能让它成为可选的?
设置required
to false
in the @RequestParam
注解,如下:
@GetMapping("/user/{user}?refresh={refresh}")
String getUser(@PathVariable String user, @RequestParam(required = false) String refresh) {
...
}