默认情况下,JeeSite 会自动生成导出代码,但有时候忘记了。这里介绍如何手动添加导出功能。
列表页增加导出按钮
在原查询按钮处。
<div class="box-tools pull-right"> <a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a> <a href="#" class="btn btn-default" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a> </div>
增加导出按钮点击事件
<script> $('#btnExport').click(function(){ js.ajaxSubmitForm($('#searchForm'), { url:'${ctx}/product/flowPaymentFreight/paymentTotalListExportData', downloadFile:true }); }); </script>
实体类中配置导出列
@ExcelFields({ @ExcelField(title="运输公司", attrName="name", align= ExcelField.Align.CENTER, sort=10), @ExcelField(title="帐期", attrName="paymentDay", align= ExcelField.Align.CENTER, sort=20), @ExcelField(title="总运费", attrName="totalAmount", align=ExcelField.Align.CENTER, sort=30), @ExcelField(title="已结算运费", attrName="payYes", align=ExcelField.Align.CENTER, sort=40), @ExcelField(title="待结算运费", attrName="payNo", align=ExcelField.Align.CENTER, sort=50), }) // 如果需要使用字典数据,增加 dictType="stock_status" 即可 // @ExcelField(title="库存状态", attrName="stockStatusCode", dictType="stock_status", align= Align.CENTER, sort=50),
控制器中增加导出方法
/** * 导出数据 */ @RequiresPermissions("customer:basicCustomerTest:view") @RequestMapping(value = "paymentTotalListExportData") public void paymentTotalListExportData(PaymentTotalList paymentTotalList, HttpServletResponse response) { List<PaymentTotalList> list = flowPaymentFreightService.findList(paymentTotalList); String fileName = "运输费用统计" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx"; try(ExcelExport ee = new ExcelExport("运输费用统计", PaymentTotalList.class)){ ee.setDataList(list).write(response, fileName); } }