导出excel 都是 存一个集合 然后利用poi 的api 导出 ,这样在数据量比较小的时候没什么问题,但是在数据量稍微大一点就会造成堆栈溢出了。所以写了一个每次导出一条记录的工具类,分享给大家!完美导出超大数据集合。不多说 ,直接贴代码
@RequestMapping("/daochu")
public void daoc(HttpServletResponse response) {
//查询你要导出的表
List list = sm.selectByExample(null);
//需要导出的字段
String[] columnNames= {“ID”,“届别”,“班级名称”,“学号”,“姓名”,“出生日期”,“性别”,“状态”,“入学日期”};
String[] columns= {“id”,“clazz”,“grade”,“number”,“name”,“birthday”,“sex”,“statu”,“starttime”,“photo”};
//调用工具类
ExcelUtils.exportExcel(response, list, columnNames, columns, “信息”, “信息表”);
}
//导入
@RequestMapping("/add")
public String add(School school,HttpServletRequest request,MultipartFile file) throws IllegalStateException, IOException {
if(!file.isEmpty()) {
String upload = FileUtils.upload(file, request);
school.setPhoto(upload);
}
sm.insertall(school);
return “redirect:list”;
}
@RequestMapping("/dels")
@ResponseBody
public int dels(String id) {
int i = sm.dels(id);
return i;
}
@RequestMapping("/toupdate")
public String toupdate(int id,Model model) {
School school = sm.selectByPrimaryKey(id);
model.addAttribute(“school”, school);
return “update”;
}
@RequestMapping("/update")
public String update(School school,MultipartFile file,HttpServletRequest request) throws IllegalStateException, IOException {
if(!file.isEmpty()){
String upload = FileUtils.upload(file, request);
}
sm.updateByPrimaryKeySelective(school);
return “redirect:list”;
}