springmvc文件导入导出

文件导出步骤:

引入问价导入导出的相关java文件; 如需要可联系qq

1、建立导出的按钮

<li class="btns"><input id="btnExport" class="btn btn-primary" type="button" value="导出"/></li>

2、导出时的提示

$("#btnExport").click(function(){
                top.$.jBox.confirm("确认要导出运营数据吗?","系统提示",function(v,h,f){
                    if(v=="ok"){
                        var searchAction = $("#searchForm").attr("action");
                        $("#searchForm").attr("action","${ctx}/operation/operationData/export");//路径
                        $("#searchForm").submit();
                        $("#searchForm").attr("action",searchAction);
                    }
                },{buttonsFocus:1});
                top.$('.jbox-body .jbox-icon').css('top','55px');
            });


3、在控制器中方法

/**
     * 导出数据(有实体)
     * 
     * @return
     */
    @RequiresPermissions("operation:operationData:view")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(OperationData operationData, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) {
        try {
            String fileName = "文件名称"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            List<OperationData> list = operationDataService.findList(operationData); 

            new ExportExcel("
文件名称(起始时
间:"+StringUtils.replaceNull(DateUtils.formatDate(operationData.getBeginDt(), "yyyy-
MM-dd"), "不限制")+",结束时
间:"+StringUtils.replaceNull(DateUtils.formatDate(operationData.getEndDt(), "yyyy-
MM-dd"), "不限
制")+")", OperationData.class).setDataList(list).write(response, fileName).dispose();
            return null;
        } catch (Exception e) {
            addMessage(redirectAttributes, "导出运营数据失败!失败信息:"+e.getMessage());
        }
        return "redirect:" + adminPath + "/modules/operation/operationDataList?repage";
    }


/**
     * 导出数据(无实体)
     * 
     * @return
     */
    @RequiresPermissions("operation:projectOperation:view")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(ProjectBaseInfo projectBaseInfo, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) {
        try {
            String fileName = "导出的文件名称"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            List<Map<String,Object>> list = projectBaseInfoService.findProjectOperationListNoPage(projectBaseInfo);
            LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
            fieldMap.put("导出列", "列名称");
            、、、、、、、、、、、、、、、、、
            new ExportExcel("文件名称", fieldMap).setDataList(list).write(response, fileName).dispose();
            return null;
        } catch (Exception e) {
            addMessage(redirectAttributes, "导出项目财务数据失败!失败信息:"+e.getMessage());
        }
        return "redirect:" + adminPath + "/modules/operation/projectOperationList?repage";
    }


4、在导出的pojo中加入注解

在get上加入@ExcelField(title="名称", align=2, sort=20)



转载于:https://my.oschina.net/hycky/blog/655270

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值