excel下载(使用线程)
来源:互联网 发布:java web 异常类型 编辑:程序博客网 时间:2024/06/05 18:51
使用线程下载excel
@PrivilegeRequired(Privilege.USER_DOWNLOAD) public Response download() throws IOException { ContentDisposition contentDisposition = ContentDisposition.type("attachment") .fileName("user".concat(".csv")).build(); final PipedOutputStream output = new PipedOutputStream(); PipedInputStream input = new PipedInputStream(output); final ListuserList = userService.listAllUsers(appBean.getClientCode()); Runnable writer = new Runnable() { @Override public void run() { //构造方法BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(output, "GBK")); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(output, "GBK"));) { StringBuilder sb = new StringBuilder(); sb.append("客户姓名").append(CSV_SEPERATOR) .append("手机号").append(CSV_SEPERATOR) .append("身份证号").append(CSV_SEPERATOR) .append("客户经理").append(CSV_SEPERATOR) .append("开户行").append(CSV_SEPERATOR) .append("银行卡").append(CSV_SEPERATOR) .append("注册时间"); bw.append(sb.toString()); bw.newLine(); for (User user : userList) { sb = new StringBuilder(); String uid = user.getId(); sb.append(user.getName() == null ? "" : user.getName()).append(CSV_SEPERATOR); sb.append(user.getMobile()).append(CSV_SEPERATOR); sb.append(user.getIdNumber() == null ? "" : user.getIdNumber()).append(CSV_SEPERATOR); if(user.getReferralEntity() ==null || user.getReferralEntity().getEntityId()== null) { sb.append("").append(CSV_SEPERATOR); }else { Employee employee =employeeBridge.findById(user.getReferralEntity().getEntityId()); sb.append(employee==null? "":StringUtils.isBlank(employee.getName()) ? "" : employee.getName()).append(CSV_SEPERATOR); } List listAcc = fundAccountService.listAccountByUser(uid, false); if(listAcc!=null && listAcc.size()>0) { sb.append(listAcc.get(0).getAccount().getBranch()==null? "":listAcc.get(0).getAccount().getBranch()).append(CSV_SEPERATOR); sb.append(listAcc.get(0).getAccount().getAccount()==null ? "":listAcc.get(0).getAccount().getAccount()).append(CSV_SEPERATOR); } else { sb.append("").append(CSV_SEPERATOR); sb.append("").append(CSV_SEPERATOR); } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); sb.append(user.getRegisterDate()==null? "": formatter.format(user.getRegisterDate())).append(CSV_SEPERATOR); bw.append(sb.toString()); bw.newLine();//写入一个行分隔符。 } bw.flush();//刷新该流中的缓冲。将缓冲数据写到目的文件中去。 } catch (Exception ex) { logger.error("Exception happened when write CSV for user list.", ex); } } }; Thread thread = new Thread(writer); thread.start(); return Response.ok(input, "text/csv").encoding("GBK").header("Content-Disposition", contentDisposition).build(); }
阅读全文
0 0
- excel下载(使用线程)
- jsp使用jxl下载excel
- Java使用jxl下载excel
- 使用poi实现Excel下载
- 使用线程下载网络图片
- servlet使用迅雷下载excel文件乱码
- 使用REST服务下载excel文件
- 使用AngularJS导出/下载excel文件
- 使用poi技术导出下载excel表格
- 使用线程池导出Excel数据
- excel 下载
- Excel下载
- excel下载
- excel下载
- (四)线程--使用线程回调方法(示例下载)
- (四)线程--使用线程回调方法(示例下载)
- (四)线程--使用线程回调方法(示例下载)
- 线程--使用线程回调方法(示例下载)
- Vue-cli安装和使用
- 类加载过程
- Android Studio新功能解析,你真的了解Instant Run吗?
- Android检查更新下载安装
- unity的触摸类touch使用
- excel下载(使用线程)
- 织梦DedeCMS简略标题
- AlphaGo的原理
- 在Ubuntu中设置samba共享可读写文件夹
- 小试4解析
- 拨开字符编码的迷雾--MySQL数据库字符编码
- 慕课网编程练习:制作一个表格,显示班级的学生信息。
- YJCocoa Gem开源库
- 软件测试学习6-动态白盒测试