(1)前端下载按钮:
<a href="/controller/downloadModel?filename=xx.xls" class="btn btn-danger radius"> 导出模板</a>
(2)后端代码:
@RequestMapping("/downloadModel")
@ResponseBody
public ModelAndView fileDownLoad(HttpServletRequest request, HttpServletResponse response, String filename)throws Exception{
response.setHeader("Content-Disposition","attachment;fileName="+filename);
String realPath=(File.separator + "root"+File.separator+"model"+File.separator+filename);
InputStream is = new FileInputStream(realPath);
OutputStream os = response.getOutputStream();
IOUtils.copy(is,os);
os.close();
is.close();
return null;
}