@ApiOperation(value = "下载模板")
@GetMapping("/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, FinanceException {
userManagementService.download(request,response);
}
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, FinanceException {
InputStream inStream = getClass().getClassLoader().getResourceAsStream("excel/user.xlsx");
if (null != inStream) {
try {
// 设置输出的格式
response.reset();
response.setContentType("application/vnd.ms-excel");
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
response.addHeader("Access-Control-Allow-Headers", "Content-Type");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("excel/人员修改模板.xlsx", "UTF-8"));
// 循环取出流中的数据
byte[] b = new byte[200];
int len;
while ((len = inStream.read(b)) > 0) {
response.getOutputStream().write(b, 0, len);
}
inStream.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != inStream) {
try {
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
throw new FinanceException(111,"获取excle错误,请联系管理员");
}
![]()