J示例代码:

    @ResponseBody
	@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
	public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		PrintWriter writer = null;
		String orgfilename = "";
		
		String dataRandomNum = request.getParameter("dataRandomNum");
		String filePath = "";

		String path = Toolkit.getConfigValue("bd.sys.config.lzzb.filepath","C:\\Users\\Administrator\\AppData\\Local\\Temp\\HeiFei");
		filePath = path+"\\"+dataRandomNum;

		MultipartHttpServletRequest mhsr  =  (MultipartHttpServletRequest) request;  
		    //(根据前台的name名称得到上传的文件)   
		Iterator<String> isFiles = mhsr.getFileNames();
		
		while (isFiles.hasNext()) {
	            MultipartFile file = mhsr.getFile(isFiles.next());
	            String fileNames = file.getOriginalFilename();
	            orgfilename = fileNames;
	            File headPath = new File(filePath);// 获取文件夹路径
	            if (!headPath.exists()) {// 判断文件夹是否创建,没有创建则创建新文件夹
	            	headPath.mkdirs();
	            }
	            OutputStream out = new FileOutputStream(new File(filePath, fileNames));
	            InputStream in = file.getInputStream();
	            int length = 0;
	            byte[] buf = new byte[1024];
	            while ((length = in.read(buf)) != -1) {
	            	out.write(buf, 0, length);
	            }
	            in.close();
	            out.close();
	            /** 将上传处理后的数据返回 **/
	            map.put("orgfilename", orgfilename);
	            map.put("filepath", (filePath + "\\" + orgfilename));
	            map.put("success", 200);
	            map.put("code", "200");
	            	
	        }
	
		response.setContentType("text/xml; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		writer = response.getWriter();
		String msg = JSON.toJSONString(map);
	
		Boolean returnB = cyanobacteriaWeeklyService.insertCyanobacteriaWeeklyData(filePath);
		
		if(returnB) {
		   	map.put("data", "插入成功!");
		   }else {
		   	map.put("data", "插入失败!");
		   }
		
		writer.print(msg);
		
	}
    
    @ResponseBody
    @RequestMapping(value = "/exportFile")
    public void exportFile(HttpServletRequest request, HttpServletResponse response) {
    	
    	String startTime = request.getParameter("startTime");
    	String endTime = request.getParameter("endTime");
    	
        //省略数据处理
    	
    	//获取运行环境路径
    	java.net.URL uri = this.getClass().getResource("/");
    	String filePash = uri.getPath();
    	filePash = filePash.substring(1, filePash.indexOf("WEB-INF"))+"resources/file/蓝藻藻情报告_20200708.docx";
    	
    	//render
    	XWPFTemplate template = XWPFTemplate.compile(filePash).render(dataMap);
    	
    	OutputStream out = null;
		try {
			
			String  fileName = year+"年"+month+"月巢湖蓝藻藻情报告.docx";
			//1、设置response 响应头
			response.reset();
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/octet-stream");
			response.setHeader("Content-Disposition","attachment;fileName="+URLEncoder.encode(fileName, "UTF-8"));
			
			//3、 写出文件--输出流
			out = response.getOutputStream();
	    	template.write(out);
	    	template.close();
	    	out.close();

		} catch (FileNotFoundException e) {
			LOGGER.error(e.getMessage());
		} catch (IOException e) {
			LOGGER.error(e.getMessage());
		}finally {
			try {
				if(template != null) {
					template.close();
	    		}
			} catch (IOException e) {
				LOGGER.error(e.getMessage());
			}
	    	try {
	    		if(out != null) {
	    			out.close();
	    		}
			} catch (IOException e) {
				LOGGER.error(e.getMessage());
			}
		}
    }

包含:获取Class数据路径,文件导入和导出