当前位置: 首页 > news >正文

清远网站建设公司网站备案制度

清远网站建设公司,网站备案制度,专业专业的网站开发,1卡二卡三卡四卡精品hd说明 通过接口&#xff0c;导出表格。 使用SpringBoot框架和easypoi表格解析框架&#xff0c;生成Excel表格&#xff0c;并通过接口下载。 表格示例 依赖 版本 <easypoi.version>4.4.0</easypoi.version>依赖 <!-- easypoi --> <dependency><…

说明

通过接口,导出表格。

使用SpringBoot框架和easypoi表格解析框架,生成Excel表格,并通过接口下载。

表格示例

在这里插入图片描述

依赖

版本

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

依赖

<!-- 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("导出用户列表(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 {// 获取用户表格对象列表List<UserExcel> userExcelList = listUserExcel();// 获取表格下载的输出流OutputStream outputStream = FileUtil.getExcelOutputStream("用户列表.xlsx", response);// 导出表格ExcelExportUtil.exportExcel(new ExportParams("用户列表(抬头)", "sheet"), UserExcel.class, userExcelList).write(outputStream);}/*** 获取用户表格对象列表*/private List<UserExcel> listUserExcel() {List<UserEntity> userEntities = listUserEntity();// 将查询出来的 数据库Entity,转换为 Excel实体 。return userEntities.stream().map(item -> {UserExcel vo = new UserExcel();BeanUtils.copyProperties(item, vo);return vo;}).collect(Collectors.toList());}/*** 模拟从数据库查询出数据列表。*/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客户");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("客户已禁用");return Stream.of(user1, user2).collect(Collectors.toList());}}

表格实体

package com.example.data.excel;import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
import lombok.Data;/*** 用户信息-Excel对象;** @author : songguanxun* @date : 2023-9-8*/
@Data
@ApiModel(value = "用户-Excel对象")
public class UserExcel {@Excel(name = "姓名", orderNum = "1", width = 30)private String name;@Excel(name = "账号", 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 = "账号状态", orderNum = "5", replace = {"启用_1", "禁用_2"}, width = 20)private Integer status;@Excel(name = "备注", orderNum = "6", width = 50)private String remark;}

数据库实体

package com.example.db.entity;import lombok.Data;/*** 用户** @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;}

文件工具类

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;/*** 文件工具类*/
public class FileUtil {/*** 获取表格下载的输出流** @param fileName 文件名* @param response 接口响应对象* @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.yayakq.cn/news/452059/

相关文章:

  • 中山教育平台网站建设装修设计图纸效果图
  • 宿松网站建设成都小程序推广企业
  • 东莞做网站需要多少钱景区网站如何建设
  • 网站需要去工信部做备案吗深圳网站(建设信科网络)
  • 网站建设如何上传图片网站建设seo策略有哪些
  • 厦门建设网站企业苏州百度运营公司排名
  • 徐州网站建设方案咨询网页制作基础教程我的足球网
  • app备案查询网站免费商城网站
  • 设计一个网站需要什么成都网上房地产
  • 免费链接生成器太原百度搜索排名优化
  • 江苏建设人才考试网官方网站网页设计基础实训报告
  • 河北网站建设seo优化招商加盟类网站模板
  • 老域名网站不收录天津做网站最权威的公司
  • 企业网站需要哪些模块建设网站q8555 3807
  • 只做网站不做app企业网站的维护工作要怎么做
  • 发任务做任务得网站最好用的cms
  • 先做网站 先备案wordpress 前台英文
  • 专注于网络推广及网站建设通州网站建设服务
  • 公司网站修改 优帮云电子商务网站实例
  • 云南网官方网站网站素材
  • 站台建筑网站建设自我总结
  • 在国外做热情网站的风险思政部网站建设总结
  • 学网站建设可以从事什么工作猫咪社区免费资源在线观看
  • 适合迷茫年轻人的工作专业排名优化工具
  • 合肥网站排名推广孔为民医生个人网站
  • 南阳网站建设电话网站转化微信小程序
  • 公司备案查询网站备案wordpress文章发布时间
  • 免费网站建设c3sales大企业门户网站建设
  • 10G网站空间pageadmin是免费的吗
  • 可信网站认证哪里有做网站接电话一般要会什么问题