/**
* 下载导入模板
*
* @return
*/
@RequestMapping(value = "/downloadExcel", method = RequestMethod.GET)
@ExcludeAuthentication
public void downloadExcel(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
String fileName = new String("导入模板.xlsx".getBytes("GBK"),"ISO8859-1");
// 读到流中
InputStream inStream = null;
OutputStream out = null;
inStream = this.getClass().getResourceAsStream ("/model/readerImprotModel.xlsx");
// 设置输出的格式
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.addHeader("Content-Disposition", "attachment;filename=" +fileName);
// 循环取出流中的数据
byte[] b = new byte[1024];
int len;
try {
while ((len = inStream.read(b)) > 0) {
out = response.getOutputStream();
out.write(b, 0, len);
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inStream != null) {
inStream.close();
}
if (out!=null){
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
http下载模板
最新推荐文章于 2023-01-08 16:26:58 发布