springbootの使用は、輸出Excelのスプレッドシートを達成easypoi

 輸入依存度

<! -エクセル操作- > 
<依存> 
    <groupIdを> cn.afterturn </ groupIdを> 
    <たartifactId> easypoiスプリング・ブート・スターター</たartifactId> 
    <バージョン> 3.3.0 </バージョン> 
</依存関係> 

 

Voと定義されたエンティティクラス

@data 
@EqualsAndHashCode(= callSuper偽の)
パブリッククラスProductExportVo実装シリアライズ{ 
    プライベートロング最終静的のserialVersionUID = 1L; 
    / ** 
     *商品コード
     * / 
    @Excel(名= "項目番号"、orderNum = "0"、幅= 15 
    プライベート文字列productNo; 

    / ** 
     *商品名
     * / 
    @Excel(名= "商品名"、orderNum =、幅= 25)」1" 
    プライベート文字列商品名; 


    / ** 
     *製品タイプ
     * / 
    @Excel(名= "製品タイプ"、orderNum = "2"、幅= 15)
    プライベート文字列でProductType; 

    / ** 
     *公称値
     * / 
    @Excel(名= "リテラル"、orderNum = "3"、幅= 15) 
    プライベート整数productDeno; 

    / ** 
     *地方の販売エリア0 1 2ナショナルシティフィールド
     * / 
    @Excel(名前= "販売エリア"、orderNum = 、幅= 15)、 "4" 。
    のプライベート文字列productSalesArea; 

    / ** 
     *販売価格
     * / 
    @Excel(名= "販売価格"、orderNum =、幅= 15)" 5" 。
    プライベートBigDecimalのproductPrice; 

    / ** 
     *状態0棚1を追加しました
     * / 
    @Excel( "6"名前= "ステータス"、orderNum =、幅= 15)
    プライベート文字列productStatus; 

    / ** 
     *作成時刻
     * / 
    @Excel(名= "作成時間"を、orderNum ="7" 、幅= 25、exportFormat = "YYYY-MM-DD HH:MM:SS")
    productCreateTime文字列プライベート; 

    / ** 
     *変更 
     * / 
    (名= @Excel"改変"orderNum =" 8」、幅= 25、exportFormat = "YYYY-MM-DD HH:MM:SS")
    プライベート文字列productModifyTime。
}

  

制御層

( "製品/ exportAsExcel")@PostMapping 
公共ボイドexportAsExcel(HttpServletResponseの応答、ProductSearchDto productSearchDto){ 
    最終的な文字列名= SecurityContextHolder.getContext()getAuthentication()のgetName()。。。
    log.info( "用户[{}、{}]查导出商品表"、名前、request.getRemoteAddr())。
    IF(!。productSearchDto.getProductDenoRange()= NULL && productSearchDto.getProductDenoRange()長さ<2){ 
        productSearchDto.setProductDenoRange(NULL)。
    } 
    IF(!。productSearchDto.getProductPriceRange()= NULL && productSearchDto.getProductPriceRange()長さ<2){ 
        productSearchDto.setProductPriceRange(NULL)。
    } 
     リスト<ProductExportVo> productList = productService。 
    {試します
        ExcelUtils.exportExcel(productList、 "製品情報"、および"製品情報"、ProductExportVo.class、 "製品情報"、応答); 
    }キャッチ(IOExceptionをE){ 
        e.printStackTrace(); 
    } 

}

  

フロントエンドのVue

ダウンロード(parmas){ 
      VARのTEMP =のdocument.createElement( "フォーム")。
      temp.action = `/ API /製品/ exportAsExcel $ {qs.stringify(parmas)}`;?
      temp.method =「ポスト」。
      temp.style.display =「なし」。
      document.body.appendChild(TEMP)。
      temp.submit(); 
    }、

  

おすすめ

転載: www.cnblogs.com/song1024/p/12501751.html