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 2008远程数据库移植到本地的方法
    TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
    pycharm pip安装包
    TensorFlow深度学习,一篇文章就够了
    tf.reducemean()到底是什么意思?
    什么是Tensor
    IOS开发之自定义UITabBarController
    IOS中的网络编程详解
    高德地图JS-API (超简单Get新技能√)
    Ios开发之Category
  • 原文地址:https://www.cnblogs.com/ljc1212/p/10942942.html
Copyright © 2011-2022 走看看