当先锋百科网

首页 1 2 3 4 5 6 7

前台:

<input type="file" name="uploadfiles"  id="wkstUploadfiles"   @change="uploadWorksheetFile"   />
<script>
  return {
	 
	methods() {
         uploadWorksheetFile:function(){
        	var formData = new FormData() // 声明一个FormData对象
            this.formData = new window.FormData() // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            var uploadfiles =document.querySelector('input[type=file]').files[0];
        	if(uploadfiles !=undefined){
		 		 formData.append("files", uploadfiles) // 'files' 这个名字要和后台获取文件的名字一样;
		 	}
        	formData.append("saveType","wkst");
	       	 app.request.post("a/sys/uploadfile/uploadfile2",formData, function (data) {
                //解析处理
                
            }

    },
}

后台:

@RequiresPermissions("oa:oaNotify:edit")
@RequestMapping("/uploadfile2")
public @ResponseBody Map<String,List<Files>>  UploadFile2(ModelMap model,HttpSession session,String saveType,MultipartFile files,HttpServletRequest request) throws IOException{
	Map<String, List<Files>> map = uploadfileService.upload(files,  saveType,         
    request,session);
//这个地方是自己封装的上传文件方法,没啥特别的,不再贴出,关键还是前台代码
    return map;
}