中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

正規(guī)的品牌網(wǎng)站建設(shè)服務(wù)軟件外包網(wǎng)

正規(guī)的品牌網(wǎng)站建設(shè)服務(wù),軟件外包網(wǎng),怎么做自己地網(wǎng)站,濮陽(yáng)網(wǎng)約車(chē)說(shuō)明 通過(guò)接口&#xff0c;導(dǎo)出表格。 使用SpringBoot框架和easypoi表格解析框架&#xff0c;生成Excel表格&#xff0c;并通過(guò)接口下載。 表格示例 依賴(lài) 版本 <easypoi.version>4.4.0</easypoi.version>依賴(lài) <!-- easypoi --> <dependency><…

說(shuō)明

通過(guò)接口,導(dǎo)出表格。

使用SpringBoot框架和easypoi表格解析框架,生成Excel表格,并通過(guò)接口下載。

表格示例

在這里插入圖片描述

依賴(lài)

版本

<easypoi.version>4.4.0</easypoi.version>

依賴(lài)

<!-- easypoi -->
<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>${easypoi.version}</version>
</dependency>
<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-web</artifactId><version>${easypoi.version}</version>
</dependency>
<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-annotation</artifactId><version>${easypoi.version}</version>
</dependency>

代碼

Controller

package com.example.service;import com.example.service.UserExcelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@RestController
@RequestMapping("file")
@Api(tags = "文件")
public class FileController {@Autowiredprivate UserExcelService userExcelService;@GetMapping("export/user_excel")@ApiOperation("導(dǎo)出用戶(hù)列表(Excel表格,以附件形式下載)")public void exportUserExcel(HttpServletResponse response) throws IOException {userExcelService.downloadUserExcel(response);}}

Service

package com.example.service;import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.example.data.excel.UserExcel;
import com.example.db.entity.UserEntity;
import com.example.util.FileUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;@Service
public class UserExcelService {public void downloadUserExcel(HttpServletResponse response) throws IOException {// 獲取用戶(hù)表格對(duì)象列表List<UserExcel> userExcelList = listUserExcel();// 獲取表格下載的輸出流OutputStream outputStream = FileUtil.getExcelOutputStream("用戶(hù)列表.xlsx", response);// 導(dǎo)出表格ExcelExportUtil.exportExcel(new ExportParams("用戶(hù)列表(抬頭)", "sheet"), UserExcel.class, userExcelList).write(outputStream);}/*** 獲取用戶(hù)表格對(duì)象列表*/private List<UserExcel> listUserExcel() {List<UserEntity> userEntities = listUserEntity();// 將查詢(xún)出來(lái)的 數(shù)據(jù)庫(kù)Entity,轉(zhuǎn)換為 Excel實(shí)體 。return userEntities.stream().map(item -> {UserExcel vo = new UserExcel();BeanUtils.copyProperties(item, vo);return vo;}).collect(Collectors.toList());}/*** 模擬從數(shù)據(jù)庫(kù)查詢(xún)出數(shù)據(jù)列表。*/private List<UserEntity> listUserEntity() {UserEntity user1 = new UserEntity();user1.setId("1");user1.setName("張三");user1.setAccount("zhangsan");user1.setPassword("123456");user1.setAge(25);user1.setEmail("zhangsan@example.com");user1.setStatus(1);user1.setRemark("VIP客戶(hù)");UserEntity user2 = new UserEntity();user2.setId("2");user2.setName("李四");user2.setAccount("lisi");user2.setPassword("111222");user2.setAge(28);user2.setEmail("lisi@example.com");user2.setStatus(2);user2.setRemark("客戶(hù)已禁用");return Stream.of(user1, user2).collect(Collectors.toList());}}

表格實(shí)體

package com.example.data.excel;import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
import lombok.Data;/*** 用戶(hù)信息-Excel對(duì)象;** @author : songguanxun* @date : 2023-9-8*/
@Data
@ApiModel(value = "用戶(hù)-Excel對(duì)象")
public class UserExcel {@Excel(name = "姓名", orderNum = "1", width = 30)private String name;@Excel(name = "賬號(hào)", orderNum = "2", width = 30)private String account;@Excel(name = "年齡", orderNum = "3", width = 20)private Integer age;@Excel(name = "電子郵箱", orderNum = "4", width = 30)private String email;@Excel(name = "賬號(hào)狀態(tài)", orderNum = "5", replace = {"啟用_1", "禁用_2"}, width = 20)private Integer status;@Excel(name = "備注", orderNum = "6", width = 50)private String remark;}

數(shù)據(jù)庫(kù)實(shí)體

package com.example.db.entity;import lombok.Data;/*** 用戶(hù)** @author : songguanxun* @date : 2023-9-8*/
@Data
public class UserEntity {private String id;private String name;private String account;private String password;private Integer age;private String email;private Integer status;private String remark;}

文件工具類(lèi)

package com.example.util;import com.example.enumeration.ContentDispositionEnum;
import org.springframework.http.HttpHeaders;import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;/*** 文件工具類(lèi)*/
public class FileUtil {/*** 獲取表格下載的輸出流** @param fileName 文件名* @param response 接口響應(yīng)對(duì)象* @return 輸出流*/public static OutputStream getExcelOutputStream(String fileName, HttpServletResponse response) throws IOException {String fileNameEncoded = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());response.setHeader(HttpHeaders.CONTENT_DISPOSITION, ContentDispositionEnum.ATTACHMENT.getCode() + ";fileName=" + fileNameEncoded);return response.getOutputStream();}}
http://www.risenshineclean.com/news/54090.html

相關(guān)文章:

  • 品牌做網(wǎng)站公司長(zhǎng)沙網(wǎng)站seo服務(wù)
  • 成都網(wǎng)站制作公司有哪些百度公司怎么樣
  • 讀書(shū)網(wǎng)站建設(shè)策劃書(shū)摘要百度投訴熱線(xiàn)中心客服
  • 網(wǎng)站建設(shè)順序seo關(guān)鍵詞優(yōu)化軟件怎么樣
  • 工體網(wǎng)站建設(shè)公司論述搜索引擎優(yōu)化的具體措施
  • 我想注冊(cè)網(wǎng)站我怎么做廊坊seo排名霸屏
  • 網(wǎng)站是如何建立的網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣seo
  • 網(wǎng)站的建設(shè)及維護(hù)報(bào)告優(yōu)化營(yíng)商環(huán)境
  • wordpress代碼上傳到服務(wù)器深圳優(yōu)化seo排名
  • 網(wǎng)站頁(yè)面怎么做的好看chatgpt 鏈接
  • 做襪子娃娃的網(wǎng)站百度導(dǎo)航下載2022最新版
  • 合肥專(zhuān)業(yè)的房產(chǎn)網(wǎng)站建設(shè)怎么在百度發(fā)布信息
  • 網(wǎng)站建設(shè)需要注意什么百度信息流廣告推廣
  • 棋牌游戲網(wǎng)站怎么做的百度app關(guān)鍵詞優(yōu)化
  • 微信電腦網(wǎng)站是什么原因凡科網(wǎng)站建設(shè)
  • 保安公司網(wǎng)站如何做網(wǎng)站優(yōu)化要多少錢(qián)
  • 平邑網(wǎng)站定制太原seo軟件
  • cpa網(wǎng)站怎么做百度知道電腦版網(wǎng)頁(yè)入口
  • 用易語(yǔ)言做網(wǎng)站電商平臺(tái)排行榜前十名
  • 千圖主站的功能介紹網(wǎng)店運(yùn)營(yíng)推廣
  • 免費(fèi)創(chuàng)建個(gè)人網(wǎng)站上海網(wǎng)站快速優(yōu)化排名
  • 揚(yáng)州市建設(shè)局網(wǎng)站網(wǎng)站點(diǎn)擊量 哪里查詢(xún)
  • 揭陽(yáng)做網(wǎng)站的windows優(yōu)化大師收費(fèi)
  • 怎么做網(wǎng)站 高中信息技術(shù)百度搜索引擎下載免費(fèi)
  • 惠州網(wǎng)站建設(shè)推廣公司網(wǎng)絡(luò)營(yíng)銷(xiāo)師工作內(nèi)容
  • 網(wǎng)站建站視頻口碑營(yíng)銷(xiāo)案例2021
  • 跨境電商b2c是什么網(wǎng)站關(guān)鍵詞百度自然排名優(yōu)化
  • 天眼查公司信息查詢(xún)東莞seo優(yōu)化推廣
  • 自治區(qū)住房和城鄉(xiāng)建設(shè)部網(wǎng)站天津網(wǎng)絡(luò)推廣公司
  • 網(wǎng)站用圖片怎么交換友情鏈接