execl文件位置
经过编译后文件大小从10k变到17k
文件打开错误
pom中增加如下打包插件,可以过滤掉execl文件不进行编译
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.6</version>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
@GetMapping("/download/template")
public void downloadTemplate(HttpServletResponse response) throws Exception {
String file = this.getClass().getClassLoader().getResource("").getFile() + "template/person_template.xlsx";
try (ServletOutputStream outputStream = response.getOutputStream()) {
byte[] bytes = FileUtil.readBytes(new File(file));
//响应客户端浏览器区分数据
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=person_template.xlsx");
response.setCharacterEncoding("utf-8");
IoUtil.write(outputStream, true, bytes);
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
}
}