我有这个端点(删除所有不相关的东西),并希望看到如何直接从Param Map获取文件名列表:
即:http://localhost:8080/files?file=first&file=second&file=third
@RequestMapping(path = "/files",
method = RequestMethod.GET)
public void getFiles(@RequestParam(value = "file",
required = true) String[] files,
@RequestParam Map<String, Object> params) {
for (String file : files) { // this works, all get printed
logger.info("file: " + file);
}
// this, however, only gives the first entry not the whole list
//
logger.info("params.get(file): " + params.get("file"));
}
答案 0 :(得分:0)
地图不能包含具有相同键的多个值。由于多个参数具有相同的名称(file
),因此只保留一个值。
要处理具有相同密钥的多个参数的查询,请使用MultiValueMap<String, Object>
。多值图是
存储多个值的Map接口的扩展。