1
我使用Spring-MVC 3,并在我的应用程序中,我发送一些信息 与多个附件,每个文件有一个标题,Id等。所以,我做了一个DTO如下JsonMappingException:无法构建CommonsMultipartFile的实例
public class MyDTO {
Long id;
Integer age;
MultipartFile infoFile;
// getter setter
我按照上面DTO类在我JS
文件只是创造一个JSON
对象。
这是我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: [email protected]; line: 1, column: 336] (through reference chain: com.avi.dto.MyDTO["hbvFile"])
它可能需要一个没有参数的构造函数,'CommonsMultipartFile'没有一个。 –
你可以展示你的'JSON'看起来像什么吗? –