注解方式传LIST@RequestBody

时间:2024-04-17 20:06:24

在SpringMVC中使用注解方式传List类型的参数时,要使用@RequestBody注解而不是@RequestParam注解

     //创建文件夹
@RequestMapping(value="api/createFolders",method=RequestMethod.POST)
@ResponseBody
public ClientResponse<LinkedHashMap<String, BookFsApiJson>> createFolders(
@RequestParam("bookId") long bookId,
@RequestParam("parentId") long parentId,
@RequestBody List<String> paths,
HttpServletRequest request) {
int userId = loginService.getCurrentUserId(request);
LinkedHashMap<String, BookFs> pathBookFsMap = mService.createFolders(bookId, userId, parentId, paths);
LinkedHashMap<String, BookFsApiJson> pathBookFsJsonMap = new LinkedHashMap<>();
for (Map.Entry<String, BookFs> entry : pathBookFsMap.entrySet()) {
pathBookFsJsonMap.put(entry.getKey(), BookFsConverter.ConvertDomToJson(entry.getValue()));
}
return ClientResponse.success(pathBookFsJsonMap);
}