欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

分布式醫(yī)療掛號(hào)系統(tǒng)EasyExcel導(dǎo)入導(dǎo)出數(shù)據(jù)字典的使用

 更新時(shí)間:2022年04月25日 08:54:16   作者:Hudie.  
這篇文章主要為大家介紹了分布式醫(yī)療掛號(hào)系統(tǒng)EasyExcel導(dǎo)入導(dǎo)出數(shù)據(jù)字典的使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

一、導(dǎo)出數(shù)據(jù)字典到Excel

1.創(chuàng)建導(dǎo)出實(shí)體類

這里導(dǎo)出數(shù)據(jù)時(shí),只導(dǎo)出網(wǎng)頁(yè)上每條記錄的id、父id、名稱、編碼、值。

@Data
public class DictEeVo {
    @ExcelProperty(value = "id", index = 0)
    private Long id;
    @ExcelProperty(value = "上級(jí)id", index = 1)
    private Long parentId;
    @ExcelProperty(value = "名稱", index = 2)
    private String name;
    @ExcelProperty(value = "值", index = 3)
    private String value;
    @ExcelProperty(value = "編碼", index = 4)
    private String dictCode;
}

2.后臺(tái)接口代碼

Controller層

為了實(shí)現(xiàn)下載數(shù)據(jù),Controller層傳入HttpServletResponse 參數(shù)。

    @ApiOperation(value = "導(dǎo)出數(shù)據(jù)字典接口")
    @GetMapping("exportData")
    public void exportDictData(HttpServletResponse response) throws IOException {
        dictService.exportDictData(response);
    }

Service層

Service接口:

void exportDictData(HttpServletResponse response) throws IOException;

Service實(shí)現(xiàn)類:

實(shí)現(xiàn)類中,首先設(shè)置響應(yīng)類型、響應(yīng)頭、編碼等信息。然后通過(guò)Dao層方法查詢數(shù)據(jù)庫(kù),先將查詢到的數(shù)據(jù)放在dictList集合中,再通過(guò)BeanUtils.copyProperties方法將數(shù)據(jù)放入DictVo中,最后加入dictVoList集合中,傳入write方法的參數(shù)中。

/**
     * 導(dǎo)出數(shù)據(jù)字典接口
     * @param response
     */
    @Override
    public void exportDictData(HttpServletResponse response) throws IOException {
        // 設(shè)置下載信息
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("數(shù)據(jù)字典", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=" + fileName + ".xlsx");
        // 查詢數(shù)據(jù)庫(kù)
        List<Dict> dictList = baseMapper.selectList(null);
        // 將Dict轉(zhuǎn)換為DictVo
        List<DictVo> dictVoList = new ArrayList<>();
        for (Dict dict : dictList) {
            DictVo dictVo = new DictVo();
            // 將dict中的值復(fù)制到dictVo中
            BeanUtils.copyProperties(dict, dictVo);
            dictVoList.add(dictVo);
        }
        // 調(diào)用writer方法進(jìn)行寫操作
        EasyExcel.write(response.getOutputStream(), DictVo.class).sheet("數(shù)據(jù)字典")
                .doWrite(dictVoList);
    }

3.頁(yè)面導(dǎo)出按鈕

頁(yè)面導(dǎo)出按鈕設(shè)置了超鏈接屬性,單擊后自動(dòng)調(diào)用后端下載接口。

    <a href="http://localhost:8202/admin/cmn/dict/exportData" target="_blank">
      <el-button type="text">
         數(shù)據(jù)導(dǎo)出
      </el-button>
    </a>

頁(yè)面導(dǎo)出按鈕

4.測(cè)試數(shù)據(jù)導(dǎo)出到Excel

在頁(yè)面單擊 數(shù)據(jù)導(dǎo)出 按鈕后,跳出下載框,成功將頁(yè)面數(shù)據(jù)下載到本地.xlsx文件中。

成功將數(shù)據(jù)下載到本地

二、導(dǎo)入數(shù)據(jù)字典到網(wǎng)頁(yè)

1.后臺(tái)接口代碼

Controller層

Controller層通過(guò)MultipartFile得到上傳的文件。

    @ApiOperation(value = "導(dǎo)入數(shù)據(jù)字典到網(wǎng)頁(yè)")
    @PostMapping("importData")
    public Result importDictData(MultipartFile file){
        dictService.importDictData(file);
        return Result.ok();
    }

Service層

Service接口

void importDictData(MultipartFile file);

Service實(shí)現(xiàn)類

Service中直接使用EasyExcel讀取文件中的內(nèi)容,并加載到數(shù)據(jù)庫(kù)

    @Override
    public void importDictData(MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), DictVo.class, new DictListener(baseMapper)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

配置監(jiān)聽(tīng)器

監(jiān)聽(tīng)器中,讀取Excel內(nèi)容到DictVo中,再將DictVO復(fù)制到Dict中。最后調(diào)用Dao層的方法將DIct添加到數(shù)據(jù)庫(kù)。

public class DictListener extends AnalysisEventListener<DictVo> {
    // 調(diào)用Dao
    private DictMapper dictMapper;
    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }
    // 讀取Excel內(nèi)容
    @Override
    public void invoke(DictVo DictVo, AnalysisContext context) {
        // 將DictVO對(duì)象復(fù)制到Dict中
        Dict dict = new Dict();
        BeanUtils.copyProperties(DictVo, dict);
        // 將數(shù)據(jù)添加到數(shù)據(jù)庫(kù)
        dictMapper.insert(dict);
    }
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
    }
}

2.頁(yè)面導(dǎo)入按鈕

前端頁(yè)面導(dǎo)入代碼

3.測(cè)試數(shù)據(jù)導(dǎo)入到網(wǎng)頁(yè)

在Excel中準(zhǔn)備兩條測(cè)試數(shù)據(jù):

Excel中準(zhǔn)備兩條測(cè)試數(shù)據(jù)

將Excel通過(guò)頁(yè)面的 數(shù)據(jù)導(dǎo)入 按鈕上傳到數(shù)據(jù)庫(kù):

在頁(yè)面點(diǎn)擊數(shù)據(jù)導(dǎo)入

成功將Excel中的數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù),進(jìn)而通過(guò)網(wǎng)頁(yè)展現(xiàn):

成功將Excel數(shù)據(jù)導(dǎo)入

至此,使用EasyExcel從網(wǎng)頁(yè)導(dǎo)入導(dǎo)出數(shù)據(jù)的演示已經(jīng)完成,更多關(guān)于分布式醫(yī)療掛號(hào)系統(tǒng)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java深入講解AWT實(shí)現(xiàn)事件處理流程

    Java深入講解AWT實(shí)現(xiàn)事件處理流程

    AWT的事件處理是一種委派式事件處理方式:普通組件(事件源)將整個(gè)事件處理委托給特定的對(duì)象(事件監(jiān)聽(tīng)器);當(dāng)該事件源發(fā)生指定的事件時(shí),就通知所委托的事件監(jiān)聽(tīng)器,由事件監(jiān)聽(tīng)器來(lái)處理這個(gè)事件
    2022-04-04
  • java實(shí)現(xiàn)發(fā)送手機(jī)短信

    java實(shí)現(xiàn)發(fā)送手機(jī)短信

    這篇文章主要介紹了java實(shí)現(xiàn)發(fā)送手機(jī)短信,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Java中的觀察者模式實(shí)例講解

    Java中的觀察者模式實(shí)例講解

    這篇文章主要介紹了Java中的觀察者模式實(shí)例講解,本文先是講解了觀察者模式的概念,然后以實(shí)例講解觀察者模式的實(shí)現(xiàn),以及給出了UML圖,需要的朋友可以參考下
    2014-12-12
  • SpringBoot中使用Swagger的最全方法詳解

    SpringBoot中使用Swagger的最全方法詳解

    Swagger是一個(gè)規(guī)范和完整的框架,用于生成、描述、調(diào)用和可視化Restful風(fēng)格的Web服務(wù),這篇文章主要給大家介紹了關(guān)于SpringBoot中使用Swagger的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • Java嵌入式開(kāi)發(fā)的優(yōu)勢(shì)及有點(diǎn)總結(jié)

    Java嵌入式開(kāi)發(fā)的優(yōu)勢(shì)及有點(diǎn)總結(jié)

    在本篇內(nèi)容里小編給大家整理了關(guān)于Java嵌入式開(kāi)發(fā)的優(yōu)勢(shì)及相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2022-11-11
  • Mybatis/Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn)

    Mybatis/Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn)

    本文主要介紹了Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • 關(guān)于動(dòng)態(tài)參數(shù)使用@PathVariable的解析

    關(guān)于動(dòng)態(tài)參數(shù)使用@PathVariable的解析

    這篇文章主要介紹了關(guān)于動(dòng)態(tài)參數(shù)使用@PathVariable的解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • SpringBoot整合Mybatis與thymleft實(shí)現(xiàn)增刪改查功能詳解

    SpringBoot整合Mybatis與thymleft實(shí)現(xiàn)增刪改查功能詳解

    MybatisPlus是國(guó)產(chǎn)的第三方插件,?它封裝了許多常用的CURDapi,免去了我們寫mapper.xml的重復(fù)勞動(dòng)。本文將整合MybatisPlus實(shí)現(xiàn)增刪改查功能,感興趣的可以了解一下
    2022-12-12
  • Springboot的啟動(dòng)原理詳細(xì)解讀

    Springboot的啟動(dòng)原理詳細(xì)解讀

    這篇文章主要介紹了Springboot的啟動(dòng)原理詳細(xì)解讀,springboot項(xiàng)目一般都是打包成jar包直接運(yùn)行main方法啟動(dòng),當(dāng)然也可以跟傳統(tǒng)的項(xiàng)目一樣打包war包放在tomcat里面啟動(dòng).那么springboot怎么直接通過(guò)main方法啟動(dòng)呢,需要的朋友可以參考下
    2023-11-11
  • 關(guān)于mybatis-plus插件使用時(shí)的一些問(wèn)題小結(jié)

    關(guān)于mybatis-plus插件使用時(shí)的一些問(wèn)題小結(jié)

    這篇文章主要給大家介紹了關(guān)于mybatis-plus插件使用時(shí)的一些問(wèn)題的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03

最新評(píng)論