import javax.servlet.http.HttpServletResponse;
try (Workbook wb = ExcelExportUtil.exportExcel(params, UserDTO.class, collect)) {
this.response.setContentType("application/vnd.ms-excel"); //response是注入的HttpServletResponse对象
this.response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("用户信息.xls", "UTF-8"));
ServletOutputStream out = this.response.getOutputStream();
wb.write(out);
out.flush();
out.close();
} catch (Exception e) {
log.error("Export error!", e);
Controller层方法的返回值必须设为void,不能返回其他内容,否则会报以下Warn:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation