jeesite平台导出功能

/*
* 导出:注:Controller的接口地址     student/student/student/
*/

@RequiresPermissions("student:student:student:download")
@RequestMapping("/download")
public String download(Model model,Student student,HttpServletRequest request,HttpServletResponse response ) {
List<Student> list=studentService.findList(student);
// 创建excel
HSSFWorkbook wk = new HSSFWorkbook();
// 创建一张工作表
HSSFSheet sheet = wk.createSheet();
// 2
sheet.setColumnWidth(0, 5000);
HSSFRow row = sheet.createRow(0);
// 创建第一行的第一个单元格
// 想单元格写值
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("序号");
cell = row.createCell((short)1);
cell.setCellValue("姓名");
cell = row.createCell((short)2);
cell.setCellValue("性别");
cell = row.createCell((short)3);
cell.setCellValue("生日 ");
cell = row.createCell((short)4);
cell.setCellValue("班级");

// 创建第一行
for (short i=0;i<list.size();i++)
{
row = sheet.createRow(i+1);
row.createCell(0).setCellValue(list.get(i).getSno());
row.createCell(1).setCellValue(list.get(i).getSname());
row.createCell(2).setCellValue(list.get(i).getSsex());
row.createCell(3).setCellValue(list.get(i).getSbirthday());
row.createCell(4).setCellValue(list.get(i).getSclass());
}
try {
/**
* 弹出下载选择路径框
*/
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=Student.xls");//默认Excel名称
response.flushBuffer();
wk.write(response.getOutputStream());
wk.close();
} catch (IOException e) {
e.printStackTrace();
}
finally {

}
return "null";
}

 

在html中:

<% if(hasPermi('student:student:student:download')){ %>
<a href="${ctx}/student/student/student/download" class="btn btn-default btnTool" title="${text('导出student')}"><i class="fa fa-download" aria-hidden="true"></i> ${text('导出')}</a>
<% } %>

posted @ 2020-03-12 15:56  唯恐不及  阅读(455)  评论(0编辑  收藏  举报