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 @   唯恐不及  阅读(471)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示