java - Spring MVC @PathVariable 列表输入 javax 最大大小验证
问题描述
Spring Boot-Rest API 下的 Spring MVC 项目
@GetMapping(value = "bulk/{speakerIds}")
@ResponseStatus(HttpStatus.MULTI_STATUS)
@Operation(summary = "Gets Speakers to a max Limit of 10")
public Map<Long, Object> getMasterClassBulk(@PathVariable List<Long> speakerIds) {
return speakerHandler.getSpeakers(speakerIds);
}
有没有办法添加 List Max Size 验证?eg:当输入列表超过10大小时,抛出404-Bad Request
尝试了下面的代码,但它不起作用。
@PathVariable @Size(max=10) List<Long> speakerIds
解决方案
尝试使用 @Validated 注释类并在方法参数上尝试:
@Valid @PathVariable @Size(max=10) List<Long> speakerIds
推荐阅读
- haskell - 如何从元组列表创建表
- java - 如何将字符串参数从一组允许值传递给函数
- kdb - 您可以将一个列表的元素附加到另一个列表的元素而不遍历 Q 中的列表吗?
- c# - c#中模型的继承和扩展,在base中具有多个属性实现
- matlab - 在 MATLAB 中创建时间过滤器
- r - 如果supports.transactions = FALSE,如何将R数据帧写入Access .mdb
- python - 为什么模块在实际存在时不导入?
- javascript - 问题:有什么方法可以让 Material-Table 面板一键展开或全部折叠?
- c# - 应用干净代码处理来自服务层的异常
- php - 表单提交时非对象的属性