1.application.properties
#上传文件大小限制 spring.servlet.multipart.max-file-size=500MB spring.servlet.multipart.max-request-size=500MB
2.前端
//上传 uploadServer: function (){ todata.append("FFILE", fhFile); todata.append("PARENT_ID", this.PARENT_ID); todata.append("NAME", this.pd.NAME); todata.append("REMARKS", this.pd.REMARKS); todata.append("SHARE", this.SHARE); //发送 post 请求提交保存 $.ajax({ xhrFields: { withCredentials: true }, url: httpurl+'mfolder/upload', type: 'POST', data: todata, async: false, cache: false, contentType: false, processData: false, success: function(data){ if("success" == data.result){ $("#fok").tips({ side:2, msg:'上传成功', bg:'#AE81FF', time:2 }); setTimeout(function(){ top.Dialog.close();//关闭弹窗 },1000); }else if("error" == data.result){ alert("上传失败,文件内容不能为空!"); $("#showform").show(); $("#jiazai").hide(); }else if ("exception" == data.result){ alert("文件管理"+data.exception);//显示异常 $("#showform").show(); $("#jiazai").hide(); } } }) },
3.后台
/**上传文件 www.1b23.com * @param * @throws Exception */ @RequestMapping(value="/upload") @RequiresPermissions("mfolder:add") @ResponseBody public Object add( @RequestParam(value="FFILE",required=false) MultipartFile file, @RequestParam(value="NAME",required=false) String NAME, @RequestParam(value="PARENT_ID",required=false) String PARENT_ID, @RequestParam(value="REMARKS",required=false) String REMARKS, @RequestParam(value="SHARE",required=false) String SHARE ) throws Exception{ Map<String,Object> map = new HashMap<String,Object>(); String errInfo = "success"; PageData pd = new PageData(); String ffile = DateUtil.getDays(), fileName = ""; if (null != file && !file.isEmpty()) { String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径 fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传 pd.put("FILEPATH", Const.FILEPATHFILE + ffile + "/" + fileName); //文件路径 pd.put("NAME", NAME); //文件名 pd.put("PARENT_ID", PARENT_ID); //目录ID pd.put("CTIME", DateUtil.date2Str(new Date())); //创建时间 pd.put("UNAME", Jurisdiction.getName()); //上传者,当前用户的姓名 pd.put("MASTER", Jurisdiction.getUsername()); //用户名 pd.put("FILESIZE", FileUtil.getFilesize(filePath + "/" + fileName)); //文件大小 pd.put("REMARKS", REMARKS); //备注 pd.put("SHARE", SHARE); //是否共享 pd.put("MFOLDER_ID", this.get32UUID()); //主键 mfolderService.save(pd); //存入数据库表 }else{ errInfo = "error"; } map.put("result", errInfo); //返回结果 return map; }