java excel匯出

來源:互聯網
上載者:User

標籤:https   xlsx   attribute   資料許可權   ges   catch   技術   分享   filename   

下面是jsp代碼:

<li class="btns"><input id="btnExport" class="btn btn-primary"                type="button" value="匯出所有" onclick="exports()" /></li>
function exports(){          top.$.jBox.confirm("確認要匯出所有資料嗎?","系統提示",function(v,h,f){            if(v=="ok"){            $("#searchForm").attr("action","${ctx}/record/record/record/export");            $("#searchForm").submit();            }            },{buttonsFocus:1});            top.$(‘.jbox-body .jbox-icon‘).css(‘top‘,‘55px‘);              }

下面是Controller代碼: 我這個是匯出的一對多 並且傳入的是實體類:

    @RequestMapping(value = "export")     public String exportFile(Record record, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {        try {            String fileName = "使用者資料"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";            Page<Record> page = recordService.findRecord(new Page<Record>(request, response, -1), record);            new ExportExcel("使用者資料", Record.class).setDataList(page.getList()).write(response, fileName).dispose();            return null;        } catch (Exception e) {            addMessage(redirectAttributes, "匯出失敗!失敗資訊:"+e.getMessage());        }        return "redirect:" + adminPath + "/record/record/record?repage";    }    

service層:

    public Page<Record> findRecord(Page<Record> page, Record record) {        // 產生資料許可權過濾條件(dsf為dataScopeFilter的簡寫,在xml中使用 ${sqlMap.dsf}調用許可權SQL)        record.getSqlMap().put("dsf", dataScopeFilter(record.getCurrentUser(), "o", "a"));        // 設定分頁參數        record.setPage(page);        // 執行分頁查詢        page.setList(recordDao.findList(record));        return page;    }    

想要匯出的實體類欄位的get方法上邊要寫上註解:

@ExcelField(title="模式", align=2, sort=800, fieldType=RoleListType.class)

想要通過主表匯出子表的資料

一定要在主表裡面把子表的每一個欄位都寫出來,並且產生get set方法

在get方法上邊寫上上邊的註解。

 

java excel匯出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.