修改nginx配置文件
server { # 监听的端口 listen 9001; server_name localhost; location ~ /eduservice { proxy_pass http://localhost:8001; } location ~ /eduoss { proxy_pass http://localhost:8002; } }
nginx监听9001端口,对路径中存在eduservice和eduoss的路径进行转发,注意后端接口中eduservice和eduoss是唯一的
使用EasyExcel工具对Excel读写
EasyExcel是阿里巴巴开源的一个操作excel的工具
引入依赖
<!--xls--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.1</version> </dependency>
写操作
创建实体类
@Data public class DemoData { //设置excel表头的名称 @ExcelProperty(value = "学号",index = 0) private Integer sno; @ExcelProperty(value = "姓名",index = 1) private String sname; }
调用Excel方法写文件
public static void main(String[] args) { //实现excel的写操作 //设置写入的文件路径 String filename = "E:\\MyProject\\javaProject\\guli_parent\\write01.xlsx"; //调用excel的写方法进行操作 EasyExcel.write(filename,DemoData.class).sheet("学生列表").doWrite(getData()); } //创建一个方法,返回一个list集合 public static List<DemoData> getData(){ List<DemoData> data = new ArrayList<>(); for (int i = 0; i < 10; i++) { DemoData demoData = new DemoData(); demoData.setSno(i); demoData.setSname("sname"+i); data.add(demoData); } return data; }
实现效果