av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Springboot vue導出功能實現代碼

瀏覽:3日期:2023-05-19 18:39:05

最近在工作遇到vue和Springboot 實現導出功能,翻看很多資料,發現一些博客寫法都過時了,所以自己特此記錄下,使用版本vue2,Springboot 2x以上,chrome瀏覽器 76.0.3809.100

vue 2寫法

let blob = new Blob([res.data], { type: ’application/octer-stream’ });

其中我發現很多博客用這樣的寫法,但是我發現打印res的時候沒有發現data這個參數,總是報錯后面直接用res就好了。正確寫法let blob = new Blob([res], { type: ’application/octer-stream’ });

科普一下:axios中params和data兩者,以為他們是相同的,實則不然。 因為params是添加到url的請求字符串中的,而data是添加到請求體(body)中的,最好使用params參數

import axios from ’axios’axios({method: ’post’, url: ’/user/excelExport’, responseType:‘blob’, params}).then(res => {const link = document.createElement(’a’)let blob = new Blob([res], { type: ’application/octer-stream’ });link.style.display = ’none’link.href = URL.createObjectURL(blob);link.setAttribute(’download’, fileName + ’.xlsx’);document.body.appendChild(link);link.click();document.body.removeChild(link);}).catch(err => {console.log(err)});

后臺代碼寫法 ——使用阿里巴巴的excel導出類easyexcel https://github.com/alibaba/easyexcel

<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>{latestVersion}</version></dependency>

//這里可以不用關閉流,流在方法結束,會自動關閉,通過配置product,指定返回頭 @PostMapping(path = '/user/excelExport', produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public void excelExport(WithdrawListDto withdrawListDto, HttpServletResponse response) { List<WithdrawListVo> list = withdrawService.list(withdrawListDto); ExcelWriter writer = new ExcelWriter(response.getOutputStream(), ExcelTypeEnum.XLSX, true); Sheet sheet1 = new Sheet(1, 0, WithdrawListVo.class); sheet1.setSheetName('sheet1'); writer.write(list, sheet1); }

PostMapping,加上返回頭了。前端傳過來的context-Type 要加上multipart/form-data 類型,然后在前端傳過來的url進行拼接參數,就可以進行多參數,但是不建議參數太多

例子:如/user/excelImport?account=12731564&userName=李四

@PostMapping(path = '/user/excelImport') public void excelImport(WithdrawListDto withdrawListDto,MultipartFile multipartFile) { }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 天天色影院| 夜夜嗷| 日韩一区二区在线观看视频 | a级片在线观看 | 久久久综合| 中文一区二区 | 波多野结衣乳巨码无在线观看 | 色婷婷网 | 茄子视频色 | 欧美日韩国产在线播放 | 久久视频免费 | 国产成人a亚洲精品 | 久久亚洲综合 | 亚洲激情另类 | 久草福利在线观看 | 在线欧美| 日本成片网 | 亚洲乱码在线 | 欧美日韩国产二区 | 男女免费视频 | 午夜激情网 | 午夜在线视频 | 破处视频在线观看 | 亚洲午夜视频 | 亚洲精品久久久久久久久 | 亚洲国产成人91精品 | 亚洲视频一区二区 | 国产h片在线观看 | 久久国产精 | 黄骗免费网站 | 欧美在线观看一区二区 | 亚洲小视频在线观看 | 久久久久国产 | 天天干天天草 | 看片黄全部免费 | 99久久精品一区二区成人 | 欧美九九九 | 亚洲精品伦理 | 色婷婷av一区二区三区之e本道 | 91在| 欧美在线一区二区 |