Java中导入导出后台怎么运用

导出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”;
}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值