模板文件所在地址
代码实现:
@GetMapping(value = "/downloadTemplate")
public void downFrozenTemplate(HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
ClassPathResource classPathResource = new ClassPathResource("templates/universityStudent.xlsx");
InputStream inputStream = classPathResource.getInputStream();
response.setContentType("multipart/form-data");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=universityStudent.xlsx");
OutputStream out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[1024 * 1024];
while ((b = inputStream.read(buffer)) != -1) {
out.write(buffer, 0, b);
}
inputStream.close();
out.close();
out.flush();
} catch (IOException e) {
logger.error("downloadExcel error!", e);
}
}
完成