【发布时间】:2020-11-09 18:16:07
【问题描述】:
我有一个带有两个 GET 端点的 Springboot 控制器:
@RestController
@RequestMapping("/foo")
class MyController {
fun getFoo(
@RequestParam("x", required = false) x: Int = 0
) = ...
fun getFoo(
@RequestParam("x", required = true) x: Int,
@RequestParam("y", required = true) y: Int
) = ...
我想要的行为是调用时:
-
/foo使用可选的x参数调用第一个端点。 -
/foo?x=123使用提供的x参数调用第一个端点。 -
/foo?x=123&y=456' calls the second endpoint with the suppliedxandy` 参数。
目前我收到一个错误:
{
"timestamp": "2020-07-20T13:11:24.732+0000",
"status": 400,
"error": "Bad Request",
"message": "Parameter conditions \"x\" OR \"x, y\" not met for actual request parameters: ",
"path": "/foo"
}
在指定零参数时如何确定默认端点?
【问题讨论】:
标签: spring spring-boot kotlin