国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot整合Easyexcel實(shí)現(xiàn)將數(shù)據(jù)導(dǎo)出為Excel表格的功能

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot整合Easyexcel實(shí)現(xiàn)將數(shù)據(jù)導(dǎo)出為Excel表格的功能。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

前言

本文主要介紹基于SpringBoot +MyBatis-Plus+Easyexcel+Vue實(shí)現(xiàn)缺陷跟蹤系統(tǒng)中導(dǎo)出缺陷數(shù)據(jù)的功能,實(shí)現(xiàn)效果如下圖:

springboot實(shí)現(xiàn)easyexcel,spring boot,excel,java

springboot實(shí)現(xiàn)easyexcel,spring boot,excel,java

springboot實(shí)現(xiàn)easyexcel,spring boot,excel,java

后端實(shí)現(xiàn)

EasyExcel是一個(gè)基于Java的、快速、簡(jiǎn)潔、解決大文件內(nèi)存溢出的Excel處理工具。他能讓你在不用考慮性能、內(nèi)存的等因素的情況下,快速完成Excel的讀、寫(xiě)等功能。

本文使用springboot整合easyexcel對(duì)excel文件進(jìn)行操作,來(lái)實(shí)現(xiàn)數(shù)據(jù)以excel形式導(dǎo)出的功能。

1.數(shù)據(jù)表設(shè)計(jì)

主要涉及的數(shù)據(jù)表有缺陷表、用戶表、功能模塊表,此處只展示bug表的相關(guān)內(nèi)容。

CREATE TABLE `tb_bug` (
  `id` int NOT NULL AUTO_INCREMENT COMMENT 'id',
  `bug_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '缺陷名稱',
  `bug_kind` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '缺陷類(lèi)型',
  `confirm` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0待確認(rèn)1已確認(rèn)2已拒絕',
  `priority` tinyint(1) DEFAULT NULL COMMENT '優(yōu)先級(jí),1、2、3、4',
  `status` tinyint(1) DEFAULT NULL COMMENT '0未解決1已解決',
  `creator_id` int(11) NULL DEFAULT NULL COMMENT '創(chuàng)建者id',
  `function_id` int(11) NULL DEFAULT NULL COMMENT '功能模塊id',
  `update_time` date NULL DEFAULT NULL COMMENT '更新時(shí)間',
  `designee_id` int(11) NULL DEFAULT NULL COMMENT '被指派者id',
  `solve_time` date NULL DEFAULT NULL COMMENT '解決時(shí)間',  
  `bug_remark` varchar(999) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '缺陷描述',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

2.添加依賴

<!--spring-boot啟動(dòng)依賴-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--spring-boot web依賴-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mysql依賴-->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.27</version>
</dependency>
<!--mybatis-plus啟動(dòng)依賴-->
<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-boot-starter</artifactId>
	<version>3.5.1</version>
</dependency>
<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-extension</artifactId>
	<version>3.5.1</version>
</dependency>
<!--操作Excel依賴-->
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>easyexcel</artifactId>
	<version>3.0.5</version>
</dependency>

3.實(shí)體類(lèi)

@Getter
@Setter
@TableName("tb_bug")
public class Bug implements Serializable {
     private static final long serialVersionUID = 1L;
     //id
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
     //缺陷名稱
     private String bugName;
     //缺陷類(lèi)型
     private String bugKind;
     //優(yōu)先級(jí),1、2、3、4
     private Integer priority;
     //0未解決1已解決2已關(guān)閉3激活
     private Integer status;
     //0待確認(rèn)1已確認(rèn)2已拒絕
     private Integer confirm;
     //創(chuàng)建者id
     private Integer creatorId;
     //功能模塊id
     private Integer functionId;
     //更新時(shí)間
     private Date updateTime;
     //被指派者id
     private Integer designeeId;
     //解決時(shí)間
     private Date solveTime;
     //缺陷描述
     private String bugRemark;
}

4.model類(lèi)

采用了@ExcelProperty的注解,其中value表示列名,index表示列名的索引值。

此外,還可以使用@ExcelIgnore注解,表示忽略這個(gè)字段,不導(dǎo)出這個(gè)字段的數(shù)據(jù)。

其他表格樣式注解:

@HeadRowHeight(30) ?表頭行高
@ContentRowHeight(15) ?//內(nèi)容行高
@ColumnWidth(18) ?//列寬
@ContentFontStyle(fontHeightInPoints = (short) 12) ?//字體大小

@Data
@ColumnWidth(22)
@EqualsAndHashCode
public class BugOutputExcelModel {
    @ExcelProperty("缺陷id")
    private Integer id;

    @ExcelProperty(value = "缺陷名稱")
    private String bugName;

    @ExcelProperty(value = "缺陷類(lèi)型")
    private String bugKind;

    @ExcelProperty(value = "確認(rèn)")
    private String confirm;

    @ExcelProperty(value = "優(yōu)先級(jí)")
    private Integer priority;

    @ExcelProperty(value = "缺陷狀態(tài)")
    private String status;

    @ExcelProperty(value = "創(chuàng)建者")
    private String creatorName;

    @ExcelProperty(value = "所屬項(xiàng)目")
    private String productName;

    @ExcelProperty(value = "所屬模塊")
    private String functionName;

    @ExcelProperty(value = "更新時(shí)間")
    private Date updateTime;

    @ExcelProperty(value = "被指派者")
    private String designeeName;

    @ExcelProperty(value = "解決時(shí)間")
    private Date solveTime;

    @ExcelProperty(value = "缺陷描述")
    private String bugRemark;

}

5.工具類(lèi)

public class ExcelUtil<T> {

    public static void outputExcel(HttpServletResponse response, List list, Class cla, String sheetName) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        String fileName = URLEncoder.encode(sheetName, "UTF-8");
        response.setHeader("Content-Disposition","attachment;filename="+fileName);
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
        WriteSheet sheet = EasyExcel.writerSheet(0, sheetName).head(cla).build();
        excelWriter.write(list, sheet);
        excelWriter.finish();
    }
}

6.Service類(lèi)

public interface IBugService extends IService<Bug> {
    void outputBugByExcel() throws IOException;
}
@Service
public class BugServiceImpl extends ServiceImpl<BugMapper, Bug> implements IBugService {
    @Autowired
    private BugMapper bugMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private FunctionMapper functionMapper;
    @Autowired
    private ProductFunctionMapper productFunctionMapper;    
    @Autowired
    private HttpServletResponse response;
    @Override
    public void outputBugByExcel() throws IOException {
        List<BugOutputExcelModel> list = new ArrayList<>();
        QueryWrapper<Bug> wrapper = new QueryWrapper<Bug>();
        List<Bug> bug = bugMapper.selectList(wrapper);
        for (int i=0;i<bug.size();i++){
            User creator = userMapper.selectById(bug.get(i).getCreatorId());
            User designee = userMapper.selectById(bug.get(i).getDesigneeId());
            Function function = functionMapper.selectById(bug.get(i).getFunctionId());
            QueryWrapper<ProductFunction> queryWrapper = new QueryWrapper<ProductFunction>();
            queryWrapper.eq("function_id",bug.get(i).getFunctionId());
            ProductFunction productFunction = productFunctionMapper.selectOne(queryWrapper);
            Product product = productMapper.selectById(productFunction.getProductId());
            BugOutputExcelModel model = new BugOutputExcelModel();
            //將兩個(gè)字段相同的對(duì)象進(jìn)行屬性值的復(fù)制
            BeanUtils.copyProperties(bug.get(i), model);
            String status = "";
            if (bug.get(i).getStatus()==0) status="未解決";
            else if(bug.get(i).getStatus()==1) status="已解決";
            else if(bug.get(i).getStatus()==2) status="已關(guān)閉";
            else status="激活";
            model.setStatus(status);
            String confirm="";
            if (bug.get(i).getConfirm()==0) confirm="待確認(rèn)";
            else if(bug.get(i).getConfirm()==1) confirm="已確認(rèn)";
            else confirm="已拒絕";
            model.setConfirm(confirm);
            model.setCreatorName(creator == null ? "" : creator.getRealname());
            model.setProductName(product.getProductName());
            model.setFunctionName(function.getFunctionName());
            model.setDesigneeName(designee == null ? "" : designee.getRealname());
            list.add(model);
        }
        ExcelUtil.outputExcel(response, list, BugOutputExcelModel.class, "缺陷信息");
    }
}

7.Controller類(lèi)

@RestController
@RequestMapping("/bug")
public class BugController {
    @Autowired
    private IBugService bugService;

    @ApiOperation("bug管理-導(dǎo)出全部數(shù)據(jù)excel")
    @GetMapping("/outputBugByExcel")
    public void outputBugByExcel() throws IOException {
        bugService.outputBugByExcel();
    }
}

前端實(shí)現(xiàn)

vue+springboot實(shí)現(xiàn)導(dǎo)出excel文件_weixin_53952829的博客-CSDN博客

結(jié)束語(yǔ)

感謝大家的觀看,希望對(duì)大家有幫助,有問(wèn)題可以指出!文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-623158.html

到了這里,關(guān)于SpringBoot整合Easyexcel實(shí)現(xiàn)將數(shù)據(jù)導(dǎo)出為Excel表格的功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • springboot中使用EasyExcel實(shí)現(xiàn)Excel 導(dǎo)入導(dǎo)出

    springboot中使用EasyExcel實(shí)現(xiàn)Excel 導(dǎo)入導(dǎo)出

    EasyExcel 是一款基于 Java 的簡(jiǎn)單易用的 Excel 文件操作工具。它提供了豐富的 API,可以方便地讀取、寫(xiě)入和操作 Excel 文件,支持常見(jiàn)的 Excel 操作,如讀取/寫(xiě)入單元格數(shù)據(jù)、合并單元格、設(shè)置樣式、處理大數(shù)據(jù)量等。EasyExcel能大大減少占用內(nèi)存的主要原因是在解析Excel時(shí)沒(méi)有將

    2024年02月12日
    瀏覽(40)
  • SpringBoot整合easyExcel實(shí)現(xiàn)CSV格式文件的導(dǎo)入導(dǎo)出

    目錄 一:pom依賴 二:檢查CSV內(nèi)容格式的工具類(lèi) 三:Web端進(jìn)行測(cè)試 四:拓展使用 使用hutool工具類(lèi)來(lái)進(jìn)行導(dǎo)出功能

    2024年02月02日
    瀏覽(23)
  • SpringBoot 集成 EasyExcel 3.x 實(shí)現(xiàn) Excel 導(dǎo)出

    SpringBoot 集成 EasyExcel 3.x 實(shí)現(xiàn) Excel 導(dǎo)出

    目錄 ? EasyExcel官方文檔 EasyExcel是什么? EasyExcel注解 ?springboot集成EasyExcel 簡(jiǎn)單入門(mén)導(dǎo)出 : 實(shí)體類(lèi) ?自定義轉(zhuǎn)換類(lèi) 測(cè)試一下 復(fù)雜表頭一對(duì)多導(dǎo)出 :? ?自定義注解 定義實(shí)體類(lèi) 自定義單元格合并策略 ?測(cè)試一下 ? ? EasyExcel官方文檔 EasyExcel官方文檔 - 基于Java的Excel處理工具

    2024年02月13日
    瀏覽(16)
  • 【MySQL × SpringBoot 突發(fā)奇想】全面實(shí)現(xiàn)流程 · 數(shù)據(jù)庫(kù)導(dǎo)出Excel表格文件的接口

    【MySQL × SpringBoot 突發(fā)奇想】全面實(shí)現(xiàn)流程 · 數(shù)據(jù)庫(kù)導(dǎo)出Excel表格文件的接口

    在上一篇博客,【MySQL × SpringBoot 突發(fā)奇想】全面實(shí)現(xiàn)流程 · xlsx文件,Excel表格導(dǎo)入數(shù)據(jù)庫(kù)的接口_s:103的博客-CSDN博客 我們學(xué)習(xí)了如何導(dǎo)入表格,現(xiàn)在我們反過(guò)來(lái),看看如何導(dǎo)出表格~ 網(wǎng)絡(luò)資料: View Object(視圖對(duì)象)是一種在軟件開(kāi)發(fā)中常見(jiàn)的設(shè)計(jì)模式,它用于在用戶界面

    2024年02月08日
    瀏覽(20)
  • SpringBoot 集成 EasyExcel 3.x 優(yōu)雅實(shí)現(xiàn) Excel 導(dǎo)入導(dǎo)出

    EasyExcel 是一個(gè)基于 Java 的、快速、簡(jiǎn)潔、解決大文件內(nèi)存溢出的 Excel 處理工具。它能讓你在不用考慮性能、內(nèi)存的等因素的情況下,快速完成 Excel 的讀、寫(xiě)等功能。 EasyExcel文檔地址: https://easyexcel.opensource.alibaba.com/ 引入依賴 簡(jiǎn)單導(dǎo)出 以導(dǎo)出用戶信息為例,接下來(lái)手把手教

    2024年02月15日
    瀏覽(30)
  • Java 導(dǎo)出Excel表格生成下拉框-EasyExcel
  • easyexcel根據(jù)模板導(dǎo)出Excel文件,表格自動(dòng)填充問(wèn)題

    同事在做easyexcel導(dǎo)出Excel,根據(jù)模板導(dǎo)出的時(shí)候,發(fā)現(xiàn)導(dǎo)出的表格,總會(huì)覆蓋落款的內(nèi)容。 這就很尷尬了,表格居然不能自動(dòng)填充,直接怒噴工具,哈哈。 然后一起看了一下這個(gè)問(wèn)題。 我找了自己的系統(tǒng)中關(guān)于表格導(dǎo)出的頁(yè)面,導(dǎo)出了一下,發(fā)現(xiàn)可以正常擴(kuò)充。 于是排查問(wèn)

    2024年02月06日
    瀏覽(28)
  • 基于SpringBoot + EasyExcel + Vue + Blob實(shí)現(xiàn)導(dǎo)出Excel文件的前后端完整過(guò)程

    基于SpringBoot + EasyExcel + Vue + Blob實(shí)現(xiàn)導(dǎo)出Excel文件的前后端完整過(guò)程

    首先前端發(fā)起HTTP請(qǐng)求之后,后端返回一個(gè)Excel輸出流,然后前端用Blob類(lèi)型接收數(shù)據(jù),并且解析響應(yīng)頭數(shù)據(jù)以及提取源文件名,最后用a標(biāo)簽完成下載。 一、后端代碼 (1)導(dǎo)入阿里巴巴的EasyExcel依賴(pom.xml) (2)控制層(GameController.java) (3)接口層(IGameService.java) (4)

    2024年02月16日
    瀏覽(23)
  • 使用EasyExcel實(shí)現(xiàn)excel導(dǎo)出,支持百萬(wàn)大數(shù)據(jù)量導(dǎo)出-----超簡(jiǎn)單

    通過(guò)設(shè)置sheet數(shù)量,完成分批導(dǎo)出,每個(gè)sheet存100萬(wàn)數(shù)據(jù),每次查詢插入20萬(wàn)數(shù)據(jù),避免超時(shí),內(nèi)存溢出等問(wèn)題,可以根據(jù)服務(wù)器配置調(diào)整參數(shù)設(shè)置。 1.引入依賴 2.創(chuàng)建對(duì)應(yīng)的實(shí)體類(lèi) @ExcelProperty設(shè)置的就是導(dǎo)出的列名,還可以設(shè)置排序等等 3.核心導(dǎo)出代碼 4.配置類(lèi) 至此就完成導(dǎo)

    2024年02月11日
    瀏覽(26)
  • springboot集成pagehelper以及easyExcel實(shí)現(xiàn)百萬(wàn)數(shù)據(jù)導(dǎo)出

    1.編寫(xiě)excel常量類(lèi) 2.根據(jù)數(shù)據(jù)量的不同,我們選擇不同的導(dǎo)出方法 數(shù)據(jù)量少的(20W以內(nèi)吧):一個(gè)SHEET一次查詢導(dǎo)出 數(shù)據(jù)量適中(100W以內(nèi)):一個(gè)SHEET分批查詢導(dǎo)出 ?數(shù)據(jù)里很大(幾百萬(wàn)都行):多個(gè)SHEET分批查詢導(dǎo)出 少執(zhí)行sql,優(yōu)化分頁(yè)速度,才能更快的導(dǎo)出文件

    2023年04月15日
    瀏覽(32)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包