springmvc 下载文件、中文乱码 作者:马育民 • 2021-10-14 15:23 • 阅读:10092 ``` @GetMapping("/exportMaterial") public ResponseEntity export(HttpServletRequest request, Dim dim ){ try { String uuid = UUID.randomUUID().toString().replace("-",""); String path = request.getServletContext().getRealPath("temp/"+uuid+".xls"); Material material=new Material(); material.setWmType(dim.getInventoryId()); material.setCode(dim.getKeyword()); List list=iMaterialService.query(material); POI.getExcel(list,path); File file = new File(path); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); String fileName = "原材料.xls"; headers.setContentDispositionFormData("attachment",java.net.URLEncoder.encode(fileName, "UTF-8")); return new ResponseEntity(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK); }catch (Exception e){ log.error(e); return null; } } ``` 原文出处:http://malaoshi.top/show_1IX22YhbO5Gb.html