我想接收查询字符串参数的多个值,例如:
/api/assets?category=light&category=heavy
同时将允许的值限制为预定义的集合。
我已经找到how to limit the allowed values ,现在我怎样才能允许输入多个值?
这是我当前的代码:
public ApiRespSuccess<List<AssetApi>, ApiMetadataPagination> getAssets(
@RequestParam @Parameter(schema=@Schema(description="param-desc", type="string", allowableValues= {"positioning", "energyReport"})) List<String> withExtFeature,
@ParameterObject RequestPagination pagination) {
// ...
如果我删除 @Parameter 注释,swagger-ui 会显示“添加项目”按钮。
最佳答案
这是实现目标的语法:
@GetMapping("/test")
public SampleDTO getFile(@RequestParam @Parameter(array = @ArraySchema(schema = @Schema(type = "string", allowableValues= {"positioning", "energyReport"})), description="param-desc") List<String> withExtFeature){
return null;
}
关于java - 如何允许请求参数有多个预定义(枚举)值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62684380/