【发布时间】:2017-03-27 11:41:01
【问题描述】:
我有这个端点(删除了所有不相关的)并且想看看如何直接从参数映射中获取文件名列表:
- 第一个@RequestParam 是使“文件”参数成为必需的,
- 第二个@RequestParam 是将所有参数放入地图中,而不是单独放入。
即: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"));
}
【问题讨论】:
-
问题是:如何为地图中的每个值定义一个键?这似乎有点困难,因为您的文件来自请求。
标签: spring-boot