zoukankan      html  css  js  c++  java
  • java文件下载导出

    前台代码:

    $("#btnExport").click(function(){
                    top.$.jBox.confirm("确认要导出房屋信息吗?","系统提示",function(v,h,f){
                        if(v=="ok"){
                            $("#searchForm").attr("action","${ctx}/sys_house_apply/sysHouseApply/exportsd");
                            $("#searchForm").submit();
                        }
                        $("#searchForm").attr("action","${ctx}/sys_house_apply/sysHouseApply/houseList");
                    },{buttonsFocus:1});
                    top.$('.jbox-body .jbox-icon').css('top','55px');
      })


    <input id="btnExport" style="font-size:13px; 40px;padding-left: 6px;height: 26px;padding-top: 2.5px;" class="btn btn-primary" type="button" value="导出"/>

      给导出按钮(id=”btnExport“绑定点击方法),此处使用jBox提示框 form表单提交方式

    后台代码:

    controller中代码
    @RequestMapping(value = "exportsd",method=RequestMethod.POST) public String exportproject(SysHouseApply sysHouseApply,HttpServletRequest request,  //SysHouseApply:前台form表单中的对象 HttpServletResponse response,RedirectAttributes redirectAttributes)throws Exception{ List<SysHouseApply> waitList = new ArrayList<SysHouseApply>() ;//查询需要的数据try{ SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");//格式化时间 String fileName = "demo"+DateUtils.getDate("yyyyMMddHHmmss");//导出的文件名 //用来存放导出的数据 List<SysHouseApplyException> exporthistor = new ArrayList<SysHouseApplyException>(); for(int i=0;i<waitList.size();i++){ SysHouseApplyException obj1 = new SysHouseApplyException();
                obj1.setHouseId(waitList.get(i).getHouseId());//将查询出的数据 set到要导出的文件对象中
                exporthistor.add(obj1); } new ExportExcel("房屋信息", SysHouseApplyException.class).setDataList(exporthistor).write(response, fileName).dispose();//SysHouseApplyException导出文件对象 return null; } catch (Exception e) { addMessage(redirectAttributes, "导出房屋信息失败!失败信息:"+e.getMessage()); } return "redirect:"+Global.getAdminPath()+"/sys_house_apply/sysHouseApply/houseList?repage";//页面查询连接 }

    SysHouseApplyException导出文件对象

    /**
    * 租房信息Entity
    */
    public class SysHouseApplyException extends DataEntity<SysHouseApplyException> {

      private static final long serialVersionUID = 1L;
      private String houseId;//房屋Id


      @ExcelField(title="房屋ID", align=2, sort=1)
      public String getHouseId() {
      return houseId;
      }

      public void setHouseId(String houseId) {
      this.houseId = houseId;
      }

    }

  • 相关阅读:
    SQL Server 内存数据库原理解析
    SQL Server 利用游标解决Tempdb究极竞争-DBA-程序员需知
    SQL Server 利用锁提示优化Row_number()-程序员需知
    SQL Server并行死锁案例解析
    SQL Server In-Memory OLTP 无损PPT分享
    SQL Server优化器特性-动态检索
    SQL Server 隐式转换引发的躺枪死锁-程序员需知
    SQL Server 优化器特性导致的内存授予相关BUG
    SQL Server优化器特性-位图过滤(Bitmap)
    SQL Server优化技巧之SQL Server中的"MapReduce"
  • 原文地址:https://www.cnblogs.com/ljc1212/p/10942942.html
Copyright © 2011-2022 走看看