springMVC文件上传
来源:互联网 发布:几何网络是什么意思 编辑:程序博客网 时间:2024/06/06 19:58
@RequestMapping(params = "doAdd") public ModelAndView doAdd(ProjectMainAttEntity projectMainAtt, HttpServletRequest request, @RequestParam("file") MultipartFile[] file) { String message = null; message = "待审核经费添加成功"; String yyyyMM = DateUtils.date2Str(DateUtils.date_yyyy_mm); String path = request.getSession().getServletContext().getRealPath("upload/") + "/" +"moneyfile"+"/" + yyyyMM + "/"; String[] detailNames = request.getParameterValues("detailName"); //明细名称 String[] detailMoneys = request.getParameterValues("detailMoney"); //实际支出金额 String[] realDateArray = request.getParameterValues("realDate"); //实际支出时间 int i = 0;//经费明细索引 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //字符串转时间 try{ projectMainAtt.setCheckedStatus("0"); projectMainAttService.save(projectMainAtt); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "待审核经费添加失败"; throw new BusinessException(e.getMessage()); } //明细存储 for(MultipartFile f:file){ String fileName = f.getOriginalFilename().substring(0,f.getOriginalFilename().lastIndexOf("."));//文件名 String fileType = f.getOriginalFilename().substring(f.getOriginalFilename().lastIndexOf(".")+1);//文件名 String targetFileName = this.pmMoneyFileService.targetFileName(fileType); PmMoneyFileEntity moneyFileEntity = new PmMoneyFileEntity(); moneyFileEntity.setDetailName(detailNames[i]); moneyFileEntity.setDetailMoney(detailMoneys[i]); Date realDate = null; try { realDate = sdf.parse(realDateArray[i]); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } moneyFileEntity.setRealDate(realDate); //制造文件存放相对路径 String filePath="upload" + "/" + "moneyfile"+ "/" + yyyyMM + "/"; filePath = filePath + targetFileName;//相对路径 moneyFileEntity.setFilePath(filePath); moneyFileEntity.setFileName(fileName); moneyFileEntity.setDocumentId(projectMainAtt.getId()); try { pmMoneyFileService.save(moneyFileEntity); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } File targetFile = new File(path,targetFileName); //如果文件夹不存在 就创建文件夹 if(!targetFile.exists()){ targetFile.mkdirs(); } try { f.transferTo(targetFile); //上传文件至服务器指定路径(path) } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } i++; } request.setAttribute("message", message); request.setAttribute("returnURL", "projectMainAttController.do?list"); return new ModelAndView("success"); }
阅读全文
0 0
- springMVC(11) springMVC文件上传
- SpringMVC-----8、SpringMVC上传文件
- springmvc文件上传总结
- SpringMVC multipart文件上传
- SpringMVC中的文件上传
- springmvc的文件上传
- springMVC上传文件
- springMVC 文件上传
- SpringMVC - 文件上传篇
- springMVC文件上传
- springMVC文件上传
- springMVC文件上传
- SpringMVC 上传文件
- SpringMVC文件上传
- springMVC上传文件
- springMVC上传文件例子
- springMVC上传文件
- springmvc文件上传错误
- Unity3D NGUI UIInput中文输入,插入文本时后面文本被删除问题
- 基于ARM板的打印机程序
- JAVA中常用的加密算法(Hash、base64、MD5、ASC)
- Apache Maven项目提供的Compiler插件详解
- 自己动手模仿 springmvc 写一个 mvc框架
- springMVC文件上传
- Apache Maven项目提供的Ant插件详解
- ecache的简单配置使用
- Python 对象,实例
- DeepLearning(基于caffe)实战项目(7)--从caffe结构里函数总结一览caffe
- [一天几个linux命令] 命令执行的决断依据 ; && ||
- MacOS 开发入门
- 很好的,机器学习资料
- jquery each函数 break和continue功能