多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
导出有两种方式,datagrid导出和自定义导出,同时支持异步导出 1、datagrid导出,需有datagrid表格组件 * 默认导出:datagrid组件上定义exportId属性,指定导出按钮即可,不需要写后端java代码,导出表头与表格表头定义一致,如某些列不想导出结果中展示,可设置表头配置属性exportable:false。 同步导出:默认为同步导出 ``` <a href="javascript:void(0)" id="exportBtn"><img src="${ctx}/component/resources/images/icons/color/18/export.png" alt=""/>批量导出</a> ``` * 异步导出:需设置isAsyn=true,设置该属性后默认为即时导出,后台处理逻辑是开启新的线程进行导出,前台无需等待,可到“我的导出”菜单中查看导出进度,导出完成后显示下载按钮。 ``` <a href="javascript:void(0)" id="exportBtn" isAsyn="true"><img src="${ctx}/component/resources/images/icons/color/18/export.png" alt=""/>批量导出</a> ``` * 定时导出:设置asynExportWay="2",逻辑是前台可设置预约导出时间,后台有进程扫描,到了预约时间进行数据导出操作,导出完成后依然是到“我的导出”菜单中查看进度。 ``` <a href="javascript:void(0)" id="exportBtn" isAsyn="true" asynExportWay="2"><img src="${ctx}/component/resources/images/icons/color/18/export.png" alt=""/>批量导出</a> ``` 同时预约导出时间也可代码指定,定义dateConfig属性。时间控件用的是my97日期组件 ``` <a href="javascript:void(0)" id="exportBtn" isAsyn="true" asynExportWay="2" dateConfig="{readOnly:true, isShowClear:false, isShowToday:false, dateFmt:'yyyy-MM-dd HH:mm:ss', minDate:'%y-%M-%d 00:00:00'}"><img src="${ctx}/component/resources/images/icons/color/18/export.png" alt=""/>批量导出</a> ``` 我的导出菜单路径:${ctx}/common/exportLog/toPage 完整例子如下: ``` <!--导出按钮--> <a href="javascript:void(0)" id="exportBtn"><img src="${ctx}/component/resources/images/icons/color/18/export.png" alt=""/>批量导出</a> <!--数据表格--> <table id="dataGrid" class="easyui-datagrid" exportId="exportBtn" url="${ctx}/namelist/queryList" data-options="queryParams:$.walk.getQueryParams('conditionForm'),selectOnCheck:false,frozenAlign:'right'"> <thead data-options="frozen:true"> <tr> <th data-options="field:'oper', width:430, halign:'center', formatter:operRecord, exportable:false">操作区</th> </tr> </thead> <thead> <tr> <th data-options="field:'ck', checkbox:true, exportable:false"></th> <th data-options="field:'LIST_ID',styler:function(){return 'font-family:新宋体'}">名单制客户ID</th> <th data-options="field:'CUST_TYPE_NAME'">客户大类</th> <th data-options="field:'SUB_CUST_TYPE_NAME'">客户小类</th> <th data-options="field:'CALLING_TYPE_NAME2'">行业类型</th> <th data-options="field:'CALLING_TYPE_NAME'">行业大类</th> <th data-options="field:'CALLING_SUB_TYPE_NAME'">行业子类</th> </tr> </thead> </table> ``` 后端使用@DataExport注解进行限制导出类型 ``` @RequestMapping(value = "queryUserList") @DataExport(exportWay="1") public Object queryUserList(InParam<String, Object> inParam, Pagination pagination){ return userDemoService.queryUserList(inParam, pagination); } ``` DataExport 注解说明 ``` @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented public @interface DataExport { /** * xml文件路径 * @return */ String xml() default ""; /** * 允许导出类型。0:同步立即导出;1:异步即时导出;2:异步定时导出 * * @return */ String exportWay() default "0|1|2"; } ``` 2、自定义导出:可后台自定义表头,灵活度更高。 baseInfoBigExport1.xml ``` <?xml version="1.0" encoding="utf-8"?> <table name="名单制客户批量出"> <tr> <th field="LIST_ID" title="名单制客户ID"/> <th field="LIST_field" title="客户名称"/> <th field="CUST_TYPE" title="客户大类"/> <th field="SUB_CUST_TYPE" title="客户小类"/> <th field="CALLING_TYPE_CODE" title="行业类型"/> <th field="SUB_CALLING_TYPE_CODE" title="行业子类"/> <th field="CUST_ADDR" title="客户地址"/> <th field="CUST_MANAGER_ID" title="客户经理ID"/> <th field="MAIN_WORK" title="主营业务"/> <th field="EMPLOYEE_NUM" title="员工数量"/> <th field="EMPLOYEE_ALLOWANCE" title="员工通信补助"/> <th field="DEV_STAFF_ID" title="发展人编码"/> </tr> </table> ``` 或者复杂一点的表头 baseInfoBigExport2.xml ``` <?xml version="1.0" encoding="utf-8"?> <table name="名单制客户批量出"> <tr> <th field="LIST_ID" title="名单制客户ID" rowspan="2"/> <th field="LIST_field" title="客户名称" rowspan="2"/> <th title="员工通信补助" colspan="2"/> <th title="发展人编码" colspan="2"/> </tr> <tr> <th field="LIST_ID" title="名单制客户ID"/> <th field="LIST_field" title="客户名称"/> <th field="EMPLOYEE_ALLOWANCE" title="员工通信补助"/> <th field="DEV_STAFF_ID" title="发展人编码"/> </tr> </table> ``` 后端controller方法定义DataExport注解,指定xml路径 ``` /** * 名单制客户自定义导出示例 * * @param inParam * @param pagination * @return */ @RequestMapping(value = "/exportList") @DataExport(xml = "namelist/baseInfoBigExport1.xml") public Object exportList(InParam<String, Object> inParam, Pagination pagination) { return nameListService.queryNameList(inParam, pagination); } ``` 前端js方法 ``` //queryParams可以是json也可是参数串(param1=1&param2=2) //isAsyn为异步导出标识,同上 $.walk.exportData(url, queryParams, isAsyn); ```