springmvc非参数列表接收上传多个文件
Posted cuiguangpeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springmvc非参数列表接收上传多个文件相关的知识,希望对你有一定的参考价值。
@RequestMapping(value = "/addComplaintInfo",method = RequestMethod.POST)
public HashMap<Object, Object> addComplaintInfo(ComplaintInfo complaintInfo, HttpServletRequest request) throws IOException, DocumentException
try
MultipartFile shouquanFile = null;
MultipartFile cardFile = null;
MultipartFile zuozhengFile = null;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart)
MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
shouquanFile = multipartRequest.getFile("shouquanfile");
if (null!=shouquanFile)
String originalshouquanFile = shouquanFile.getOriginalFilename();
// 文件保存路径
String filePath = GetPicUrlUtils.getPicUrl(originalshouquanFile);
// 转存文件
shouquanFile.transferTo(new File(filePath));
complaintInfo.setShouquanFileName(originalshouquanFile);
complaintInfo.setShouquanFile(filePath);
cardFile = multipartRequest.getFile("cardfile");
if (null!=cardFile)
String originalcardFile = cardFile.getOriginalFilename();
// 文件保存路径
String filePath = GetPicUrlUtils.getPicUrl(originalcardFile);
// 转存文件
cardFile.transferTo(new File(filePath));
complaintInfo.setCardFileName(originalcardFile);
complaintInfo.setCardFile(filePath);
zuozhengFile = multipartRequest.getFile("zuozhengfile");
if (null!=zuozhengFile)
String originalzuozhengFile = zuozhengFile.getOriginalFilename();
// 文件保存路径
String filePath = GetPicUrlUtils.getPicUrl(originalzuozhengFile);
// 转存文件
zuozhengFile.transferTo(new File(filePath));
complaintInfo.setZuozhengFileName(originalzuozhengFile);
complaintInfo.setZuozhengFile(filePath);
int i = this.complaintInfoService.addComplaintInfoWEB(complaintInfo); if (i > 0)
return ResultJson.success("1", "投诉登记成功!", "");
catch (Exception e)
return ResultJson.success("2", "投诉登记系统异常!", "");
return ResultJson.success("0", "投诉登记失败!", "");
以上是关于springmvc非参数列表接收上传多个文件的主要内容,如果未能解决你的问题,请参考以下文章