From 539fc5af9c7cd1e5d1f521548b79c4744af84de2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com>
Date: Wed, 29 Nov 2023 10:57:58 +0800
Subject: [PATCH] =?UTF-8?q?fix:redis=20=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 5 ++
.../controller/ExcelController.java | 37 +++++++++
.../springbootkwan/service/IExcelService.java | 9 +++
.../service/impl/IExcelServiceImpl.java | 8 ++
.../springbootkwan/utils/ExcelWriter.java | 76 +++++++++++++++++++
src/main/resources/application-local.yml | 13 ++--
6 files changed, 142 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/com/kwan/springbootkwan/controller/ExcelController.java
create mode 100644 src/main/java/com/kwan/springbootkwan/service/IExcelService.java
create mode 100644 src/main/java/com/kwan/springbootkwan/service/impl/IExcelServiceImpl.java
create mode 100644 src/main/java/com/kwan/springbootkwan/utils/ExcelWriter.java
diff --git a/pom.xml b/pom.xml
index d050202..af40b07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -244,6 +244,11 @@
gson
2.10.1
+
+ org.apache.poi
+ poi
+ 4.1.2
+
diff --git a/src/main/java/com/kwan/springbootkwan/controller/ExcelController.java b/src/main/java/com/kwan/springbootkwan/controller/ExcelController.java
new file mode 100644
index 0000000..ebb3f1d
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/controller/ExcelController.java
@@ -0,0 +1,37 @@
+package com.kwan.springbootkwan.controller;
+
+import com.kwan.springbootkwan.entity.Result;
+import com.kwan.springbootkwan.service.IExcelService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+
+/**
+ * excel测试信息
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2023/11/17 09:04
+ */
+@Slf4j
+@Api(value = "excel测试信息", tags = "ExcelController")
+@RestController
+@RequestMapping("/test")
+public class ExcelController {
+
+ @Resource
+ private IExcelService excelService;
+
+ @ApiOperation(value = "下载excel", notes = "下载excel")
+ @GetMapping("/downloadExcel")
+ public Result downloadExcel() {
+// excelService.downloadExcel();
+ return Result.ok();
+ }
+}
diff --git a/src/main/java/com/kwan/springbootkwan/service/IExcelService.java b/src/main/java/com/kwan/springbootkwan/service/IExcelService.java
new file mode 100644
index 0000000..b872fd6
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/service/IExcelService.java
@@ -0,0 +1,9 @@
+package com.kwan.springbootkwan.service;
+
+public interface IExcelService {
+
+
+
+
+
+}
diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/IExcelServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/IExcelServiceImpl.java
new file mode 100644
index 0000000..da2e4e4
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/service/impl/IExcelServiceImpl.java
@@ -0,0 +1,8 @@
+package com.kwan.springbootkwan.service.impl;
+
+import com.kwan.springbootkwan.service.IExcelService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class IExcelServiceImpl implements IExcelService {
+}
diff --git a/src/main/java/com/kwan/springbootkwan/utils/ExcelWriter.java b/src/main/java/com/kwan/springbootkwan/utils/ExcelWriter.java
new file mode 100644
index 0000000..abd89c2
--- /dev/null
+++ b/src/main/java/com/kwan/springbootkwan/utils/ExcelWriter.java
@@ -0,0 +1,76 @@
+package com.kwan.springbootkwan.utils;
+
+import com.kwan.springbootkwan.entity.User;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ExcelWriter {
+
+ private static List header = Arrays.asList("1");
+
+ public static void writeListToExcel(List dataList, String filePath, String sheetName) {
+ try (Workbook workbook = new XSSFWorkbook()) {
+ Sheet sheet = workbook.createSheet(sheetName);
+
+ // 创建标题行
+ Row headerRow = sheet.createRow(0);
+ for (int i = 0; i < dataList.size(); i++) {
+ Cell cell = headerRow.createCell(i);
+ cell.setCellValue("季节");
+ }
+
+ // 写入数据行
+ int rowNum = 1;
+ for (Object data : dataList) {
+ Row row = sheet.createRow(rowNum++);
+ CellStyle style = workbook.createCellStyle();
+ style.setWrapText(true);
+ Cell cell = row.createCell(0);
+ cell.setCellValue(data.toString());
+ cell.setCellStyle(style);
+ }
+
+ // 将Workbook写入文件
+ try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
+ workbook.write(fileOut);
+ }
+
+ System.out.println("Excel文件成功创建!");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) {
+ // 你的数据列表
+ List dataList = new ArrayList<>();
+ User user1 = new User();
+ user1.setId(1);
+ user1.setName("张三");
+ user1.setSex("男");
+ dataList.add(user1);
+ User user2 = new User();
+ user2.setId(2);
+ user2.setName("程满");
+ user2.setSex("女");
+ dataList.add(user2);
+
+ User user3 = new User();
+ user3.setId(3);
+ user3.setName("禹辰");
+ user3.setSex("男");
+ dataList.add(user3);
+ // Excel文件路径和工作表名称
+ String filePath = "/Users/qinyingjie/Downloads/file.xlsx";
+ String sheetName = "Sheet1";
+ // 调用写入Excel的方法
+ writeListToExcel(dataList, filePath, sheetName);
+ }
+}
+
diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml
index edf9698..a9050ba 100644
--- a/src/main/resources/application-local.yml
+++ b/src/main/resources/application-local.yml
@@ -15,9 +15,10 @@ spring:
required: true
redis:
database: 0 # Redis数据库索引(默认为0)
- host: 120.79.36.53 #Redis服务器地址
+# host: 43.139.90.182 #Redis服务器地址
+ host: 47.94.110.103 #Redis服务器地址
port: 6379 # Redis服务器连接端口
- password: 123456 # Redis服务器连接密码(默认为空)
+ password: zzk # Redis服务器连接密码(默认为空)
jedis:
pool:
max-active: 200 # 连接池最大连接数(使用负值表示没有限制)
@@ -32,15 +33,15 @@ spring:
kwan-ds:
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
- url: jdbc:mysql://120.79.36.53:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://43.139.90.182:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
# password: 716288qwe
- password: 15671628341Qwe.
+ password: 123456
ali-ds:
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://120.79.36.53:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://43.139.90.182:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
- password: 15671628341Qwe.
+ password: 123456
# jasypt加密的密匙
jasypt:
encryptor:
--
GitLab