SpringMVC的controller方法中注解方式传List参数使用@RequestBody

 

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

 1     //创建文件夹
 2     @RequestMapping(value="api/createFolders",method=RequestMethod.POST)
 3     @ResponseBody
 4     public ClientResponse<LinkedHashMap<String, BookFsApiJson>> createFolders(
 5             @RequestParam("bookId") long bookId,
 6             @RequestParam("parentId") long parentId,
 7             @RequestBody List<String> paths,
 8             HttpServletRequest request) {
 9         int userId = loginService.getCurrentUserId(request);
10         LinkedHashMap<String, BookFs> pathBookFsMap = mService.createFolders(bookId, userId, parentId, paths);
11         LinkedHashMap<String, BookFsApiJson> pathBookFsJsonMap = new LinkedHashMap<>();
12         for (Map.Entry<String, BookFs> entry : pathBookFsMap.entrySet()) {
13             pathBookFsJsonMap.put(entry.getKey(), BookFsConverter.ConvertDomToJson(entry.getValue()));
14         }
15         return ClientResponse.success(pathBookFsJsonMap);
16     }

 

posted on 2014-12-04 11:32  Jimmy Cheung  阅读(19448)  评论(0编辑  收藏  举报