requestParams的列表,与Enumkey和字符串值一起映射,Map< enum,string>
我正在尝试将多个请求参数组合在地图中。
我可以做到这一点,但是我们想将键限制在某些名称上,因此我们定义了枚举。
但是Spring引导没有验证地图。它只是接受,即使我们发送任何密钥而不是emum中定义的密钥。
例如:
@GetMapping("/name2")
public void getList(@RequestParam Map<FilterEnum,String> map,
@RequestParam(name = "Id", required = false) String Id) {...}
public enum FilterEnum {
lifecyclestaus,
name;
}
请求URL:
http://localhost:8090/employee/name2?bar=ks
两个问题:
- 理想情况下,它应该在上述请求中丢下错误,因为酒吧不是枚举的一部分。
- 同样,ID请求参数不应是MAP的一部分。
提前致谢。
I am trying to combine multiple request parameters in a Map.
I could do it, but we want to restrict keys to some names, hence we defined an enum.
But the spring boot doesn't validate the Map. It just accepts, even if we send any key instead of the ones defined in the emum.
Ex:
@GetMapping("/name2")
public void getList(@RequestParam Map<FilterEnum,String> map,
@RequestParam(name = "Id", required = false) String Id) {...}
public enum FilterEnum {
lifecyclestaus,
name;
}
Request URL:
http://localhost:8090/employee/name2?bar=ks
Two issues:
- Ideally it should throw an error with the above request, as bar is not part of enum.
- Also the id request param should not be part of Map.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论