【发布时间】:2021-08-08 04:00:21
【问题描述】:
我有一个这样声明的端点
@GetMapping("/shoebox")
public ResponseEntity<?> find(ShoeBox shoebox) {
...
}
当我提出像/shoebox?color=blue&size=small这样的请求时
它正确地将color 和size 绑定到一个新的ShoeBox 对象。
但是如果我像这样对@RequestParam 不关心
@GetMapping("/shoebox")
public ResponseEntity<?> find(@RequestParam ShoeBox shoebox) {
...
}
然后我得到这个错误
{
"status": 400,
"message": "Required request parameter 'shoebox' for method parameter type ShoeBoxis not present",
"timestamp": 1621373682288,
"errors": [
"MissingServletRequestParameterException"
]
}
我有点理解为什么它不适用于@RequestParam,因为我没有使用单个参数,但我不明白为什么它根本没有任何注释就可以工作。它怎么知道绑定它?此功能是否记录在任何地方?
【问题讨论】:
标签: spring spring-boot spring-mvc request spring-restcontroller