我使用Spring的MVC 3,并在我的申请,我发送带有多个附件的一些信息,每一个该文件中有一个标题,ID等,所以,我做了一个DTO如下
public class MyDTO {
Long id;
Integer age;
MultipartFile infoFile;
// getter setter
我只是创造一个JSON
按照我上面的DTO类对象JS
文件。
这里是我的Controller
的映射:
@RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
public @ResponseBody String saveInfo(
@RequestParam(value = "data", required = true) String stdData,
@RequestParam(value = "fileData", required = false) MultipartFile[] files,
HttpSession session,HttpServletRequest request) {
MyDTO dto;
try {
dto = mapper.readValue(stdData, new TypeReference<MyDTO>() {});
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但我得到以下错误:
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.springframework.web.multipart.commons.CommonsMultipartFile,
problem: no suitable creator method found to deserialize from JSON String
at [Source: java.io.StringReader@19747c9; line: 1, column: 336] (through reference chain: com.avi.dto.MyDTO["hbvFile"])