commit 19ea60d6b92905bb5e2aedeb4b7092a808cc63e6
Author: SwTt29 <2055018491@qq.com>
Date: Fri Nov 28 13:42:07 2025 +0800
Initial commit
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..3b41682
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+/mvnw text eol=lf
+*.cmd text eol=crlf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..667aaef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/CREATE_OPTIMIZATION_INDEXES.sql b/CREATE_OPTIMIZATION_INDEXES.sql
new file mode 100644
index 0000000..7251b99
--- /dev/null
+++ b/CREATE_OPTIMIZATION_INDEXES.sql
@@ -0,0 +1,81 @@
+-- 数据库索引创建脚本
+-- 此脚本用于优化应用性能,为常用查询字段创建索引
+
+-- ============================================
+-- 用户相关表索引
+-- ============================================
+
+-- users表索引
+CREATE INDEX IF NOT EXISTS idx_users_userId ON users(userId);
+CREATE INDEX IF NOT EXISTS idx_users_phoneNumber ON users(phoneNumber);
+CREATE INDEX IF NOT EXISTS idx_users_type ON users(type);
+CREATE INDEX IF NOT EXISTS idx_users_level ON users(level);
+CREATE INDEX IF NOT EXISTS idx_users_created_at ON users(created_at);
+
+-- ============================================
+-- 管理员相关表索引
+-- ============================================
+
+-- managers表索引
+CREATE INDEX IF NOT EXISTS idx_managers_id ON managers(id);
+CREATE INDEX IF NOT EXISTS idx_managers_userName ON managers(userName);
+CREATE INDEX IF NOT EXISTS idx_managers_managerId ON managers(managerId);
+CREATE INDEX IF NOT EXISTS idx_managers_organization ON managers(organization);
+CREATE INDEX IF NOT EXISTS idx_managers_managerdepartment ON managers(managerdepartment);
+
+-- ============================================
+-- 用户管理相关表索引
+-- ============================================
+
+-- usermanagements表索引
+CREATE INDEX IF NOT EXISTS idx_usermanagements_userId ON usermanagements(userId);
+CREATE INDEX IF NOT EXISTS idx_usermanagements_managerId ON usermanagements(managerId);
+CREATE INDEX IF NOT EXISTS idx_usermanagements_userName ON usermanagements(userName);
+CREATE INDEX IF NOT EXISTS idx_usermanagements_organization ON usermanagements(organization);
+CREATE INDEX IF NOT EXISTS idx_usermanagements_managerdepartment ON usermanagements(managerdepartment);
+
+-- ============================================
+-- 产品相关表索引
+-- ============================================
+
+-- products表索引
+CREATE INDEX IF NOT EXISTS idx_products_sellerId ON products(sellerId);
+CREATE INDEX IF NOT EXISTS idx_products_created_at ON products(created_at);
+
+-- ============================================
+-- 购物车相关表索引
+-- ============================================
+
+-- cart_items表索引
+CREATE INDEX IF NOT EXISTS idx_cart_items_userId ON cart_items(userId);
+CREATE INDEX IF NOT EXISTS idx_cart_items_productId ON cart_items(productId);
+
+-- ============================================
+-- 企业相关表索引
+-- ============================================
+
+-- enterprise表索引 (假设存在)
+CREATE INDEX IF NOT EXISTS idx_enterprise_id ON enterprise(id);
+CREATE INDEX IF NOT EXISTS idx_enterprise_name ON enterprise(name);
+
+-- ============================================
+-- 联系方式相关表索引
+-- ============================================
+
+-- contacts表索引
+CREATE INDEX IF NOT EXISTS idx_contacts_userId ON contacts(userId);
+
+-- ============================================
+-- 注意事项
+-- ============================================
+-- 1. 此脚本使用IF NOT EXISTS语法,可重复执行而不会报错
+-- 2. 索引创建会占用额外的磁盘空间,提高写操作开销,但显著提升查询性能
+-- 3. 建议在低峰期执行此脚本
+-- 4. 执行后建议监控应用性能,确认优化效果
+-- 5. 对于MySQL数据库,索引创建命令可能略有不同
+-- ============================================
+
+-- MySQL版本的部分索引创建语法示例(仅供参考)
+-- ALTER TABLE users ADD INDEX idx_users_userId (userId);
+-- ALTER TABLE users ADD INDEX idx_users_phoneNumber (phoneNumber);
+-- 以此类推...
\ No newline at end of file
diff --git a/DEPLOYMENT_GUIDE.md b/DEPLOYMENT_GUIDE.md
new file mode 100644
index 0000000..18a210a
--- /dev/null
+++ b/DEPLOYMENT_GUIDE.md
@@ -0,0 +1,224 @@
+# Spring Boot应用部署到Tomcat 10.1.48指南(含性能优化)
+
+## 准备工作
+
+1. **确认构建产物**:
+ - 已生成WAR文件:`web-0.0.1-SNAPSHOT.war`,位于`target`目录下
+ - 确认包含最新性能优化:SQL查询优化、分页功能、二级缓存配置
+
+2. **Tomcat环境要求**:
+ - Tomcat版本:10.1.48(Jakarta EE 10兼容)
+ - JDK版本:17或更高(与项目`pom.xml`中配置的Java版本一致)
+ - 数据库:需创建优化索引(详见数据库索引优化部分)
+
+## 部署步骤
+
+### 1. 准备部署文件
+
+```bash
+# 将WAR文件重命名为DL.war(与context-path一致)
+# 注意:在Windows命令提示符中使用
+copy target\web-0.0.1-SNAPSHOT.war target\DL.war
+
+# 或者在PowerShell中使用
+# Copy-Item -Path "target\web-0.0.1-SNAPSHOT.war" -Destination "target\DL.war"
+
+# 在Linux/Mac终端中使用(注意转义括号)
+# cp d:\java\project\web\(8)\web\target\web-0.0.1-SNAPSHOT.war d:\java\project\web\(8)\web\target\DL.war
+# 或者使用相对路径避免路径转义问题
+# cd d:\java\project\web(8)\web && cp target\web-0.0.1-SNAPSHOT.war target\DL.war
+```
+
+### 2. 上传WAR文件到服务器
+
+使用SFTP或SCP工具将`DL.war`文件上传到服务器的Tomcat目录:
+
+```bash
+# 示例:使用scp上传(注意处理路径中的括号)
+# 方法1:转义括号
+scp d:\java\project\web\(8)\web\target\DL.war user@your-server:/opt/tomcat/webapps/
+
+# 方法2:使用相对路径(推荐)
+cd d:\java\project\web(8)\web
+scp target\DL.war user@your-server:/opt/tomcat/webapps/
+
+# 方法3:使用引号包裹路径(在某些终端中有效)
+scp "d:\java\project\web(8)\web\target\DL.war" user@your-server:/opt/tomcat/webapps/
+```
+
+### 3. 确保Tomcat目录权限正确
+
+```bash
+# 登录服务器后执行
+cd /opt/tomcat
+# 确保tomcat用户对webapps目录有写权限
+chown -R tomcat:tomcat webapps/
+chmod -R 755 webapps/
+```
+
+### 4. 配置Tomcat(可选但推荐)
+
+#### 4.1 配置context.xml(解决可能的内存泄漏问题)
+
+编辑`/opt/tomcat/conf/context.xml`文件,添加以下配置:
+
+```xml
+
+
+ WEB-INF/web.xml
+ ${catalina.base}/conf/web.xml
+
+```
+
+#### 4.2 调整Tomcat内存配置
+
+编辑`/opt/tomcat/bin/setenv.sh`(如果不存在则创建):
+
+```bash
+#!/bin/bash
+# 为Tomcat设置适当的内存
+JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=256m"
+# 添加Tomcat 10兼容性参数
+JAVA_OPTS="$JAVA_OPTS --add-opens=java.base/java.lang=ALL-UNNAMED"
+```
+
+给脚本添加执行权限:
+```bash
+chmod +x /opt/tomcat/bin/setenv.sh
+```
+
+### 5. 启动或重启Tomcat
+
+```bash
+# 切换到Tomcat的bin目录
+cd /opt/tomcat/bin
+
+# 停止Tomcat(如果正在运行)
+./shutdown.sh
+
+# 等待Tomcat完全停止(约30秒)
+
+# 启动Tomcat
+./startup.sh
+```
+
+### 6. 验证部署
+
+1. **检查Tomcat日志**:
+ ```bash
+ tail -f /opt/tomcat/logs/catalina.out
+ ```
+
+2. **访问应用**:
+ - 应用应该可以通过以下URL访问:`http://your-server-ip:8080/DL`
+ - 登录页面:`http://your-server-ip:8080/DL/loginmm.html`
+
+## 常见问题排查
+
+### 1. 端口冲突
+
+如果Tomcat的8080端口已被占用,修改`/opt/tomcat/conf/server.xml`中的端口配置:
+
+```xml
+
+```
+
+### 2. 数据库连接问题
+
+确保数据库服务器允许来自Tomcat服务器IP的连接。检查应用配置中的数据库连接URL是否正确。
+
+### 3. 类加载问题(Tomcat 10特有)
+
+Tomcat 10使用Jakarta EE,所有`javax.*`包已改为`jakarta.*`。如果出现类找不到的错误:
+
+- 检查是否有冲突的JAR包在WEB-INF/lib中
+- 确保使用的是支持Jakarta EE的依赖版本
+
+### 4. 内存溢出
+
+如果出现内存溢出错误,增加Tomcat的内存分配,修改`setenv.sh`文件:
+
+```bash
+JAVA_OPTS="-Xms1024m -Xmx2048m -XX:MaxPermSize=512m"
+```
+
+## 数据库索引优化(重要)
+
+在部署新版本前,请在数据库服务器上执行以下索引创建脚本,以提升查询性能:
+
+```sql
+-- 执行CREATE_OPTIMIZATION_INDEXES.sql文件中的脚本
+-- 在服务器上执行:
+source /path/to/CREATE_OPTIMIZATION_INDEXES.sql
+
+-- 或直接复制脚本内容执行
+
+-- 1. 为managers表创建索引
+CREATE INDEX idx_managers_enterprise_id ON managers(enterprise_id);
+CREATE INDEX idx_managers_user_name ON managers(user_name);
+
+-- 2. 为users表创建索引
+CREATE INDEX idx_users_user_id ON users(user_id);
+CREATE INDEX idx_users_user_name ON users(user_name);
+CREATE INDEX idx_users_status ON users(status);
+
+-- 3. 为usermanagements表创建索引
+CREATE INDEX idx_usermanagements_user_id ON usermanagements(user_id);
+CREATE INDEX idx_usermanagements_role_id ON usermanagements(role_id);
+CREATE INDEX idx_usermanagements_permission_level ON usermanagements(permission_level);
+```
+
+## 应用更新流程
+
+1. **执行数据库索引优化**:按照上方数据库索引优化部分执行索引创建脚本
+2. **停止Tomcat**:`./shutdown.sh`
+3. **备份旧数据**:`cp -r /opt/tomcat/webapps/DL /path/to/backup/`
+4. **删除旧的WAR文件和解压目录**:`rm -rf /opt/tomcat/webapps/DL*`
+5. **上传新的WAR文件**
+6. **启动Tomcat**:`./startup.sh`
+7. **监控日志确认部署成功**:`tail -f /opt/tomcat/logs/catalina.out`
+
+## 性能优化验证
+
+部署完成后,请执行以下验证步骤确认性能优化效果:
+
+1. **验证分页功能**:
+ - 访问负责人管理页面,确认列表显示已启用分页
+ - 验证翻页功能正常,数据加载速度提升
+
+2. **验证SQL查询性能**:
+ - 执行常用查询操作,确认响应时间明显改善
+ - 监控数据库慢查询日志,检查是否有新的慢查询
+
+3. **验证缓存效果**:
+ - 连续访问相同数据页面,确认第二次访问速度更快
+
+## 回滚方案
+
+如遇部署问题,请按以下步骤回滚:
+
+1. 停止Tomcat:`./shutdown.sh`
+2. 删除新部署文件:`rm -rf /opt/tomcat/webapps/DL*`
+3. 恢复备份:`cp -r /path/to/backup/DL /opt/tomcat/webapps/`
+4. 恢复数据库索引(如需要)
+5. 启动Tomcat:`./startup.sh`
+
+## 注意事项
+
+1. **备份**:部署前请备份现有应用数据和配置
+2. **维护窗口**:选择低流量时段进行部署
+3. **监控**:部署后密切监控应用性能和日志
+4. **权限**:确保Tomcat用户对所有必要目录有正确权限
+5. **性能监控**:部署后持续监控系统性能指标,必要时进行进一步优化
+6. **索引维护**:定期检查数据库索引使用情况和碎片
+
+---
+
+部署时间:2024
+版本:2.0(包含性能优化)
+
+---
+
+> 详细性能优化说明请参考:PERFORMANCE_OPTIMIZATION_GUIDE.md
\ No newline at end of file
diff --git a/DL.war b/DL.war
new file mode 100644
index 0000000..8086386
Binary files /dev/null and b/DL.war differ
diff --git a/LATEST_DEPLOYMENT_GUIDE.md b/LATEST_DEPLOYMENT_GUIDE.md
new file mode 100644
index 0000000..b38fdfe
--- /dev/null
+++ b/LATEST_DEPLOYMENT_GUIDE.md
@@ -0,0 +1,184 @@
+# Spring Boot应用最新部署指南(性能优化版)
+
+## 版本信息
+- **版本**: 2.0
+- **日期**: 2024
+- **更新内容**: 包含数据库性能优化、SQL查询优化、分页功能和缓存配置
+
+## 一、优化内容概述
+
+### 1.1 已完成的性能优化
+
+#### SQL查询优化
+- 将`SELECT *`查询替换为显式字段列表,减少数据传输量
+- 优化复杂JOIN查询,减少不必要的表连接
+
+#### 分页功能实现
+- 新增`selectAllManagersWithPagination`方法实现分页查询
+- 添加`getManagersCount`方法获取总数用于分页计算
+
+#### 缓存配置
+- 为ManagersMapper添加LRU二级缓存配置
+- 提升重复查询性能
+
+#### 数据库索引
+- 为关键字段创建索引,提升查询性能
+- 详细索引脚本位于`CREATE_OPTIMIZATION_INDEXES.sql`
+
+## 二、部署前准备
+
+### 2.1 确认构建产物
+- **WAR文件**: `target\web-0.0.1-SNAPSHOT.war`
+- **索引脚本**: `CREATE_OPTIMIZATION_INDEXES.sql`
+- **验证文件**: `src\main\resources\mapper`目录下的优化后的XML文件
+
+### 2.2 环境要求
+- **Tomcat**: 10.1.48(Jakarta EE 10兼容)
+- **JDK**: 17或更高
+- **数据库**: 支持索引创建的关系型数据库
+
+## 三、部署流程
+
+### 3.1 本地准备部署文件
+
+```bash
+# 1. 清理并构建项目
+mvn clean package -DskipTests
+
+# 2. 重命名WAR文件
+copy target\web-0.0.1-SNAPSHOT.war target\DL.war
+```
+
+### 3.2 数据库索引优化(关键步骤)
+
+在数据库服务器上执行索引创建脚本:
+
+```sql
+-- 执行CREATE_OPTIMIZATION_INDEXES.sql文件
+-- 或直接执行以下索引创建语句
+
+-- 为managers表创建索引
+CREATE INDEX idx_managers_enterprise_id ON managers(enterprise_id);
+CREATE INDEX idx_managers_user_name ON managers(user_name);
+
+-- 为users表创建索引
+CREATE INDEX idx_users_user_id ON users(user_id);
+CREATE INDEX idx_users_user_name ON users(user_name);
+CREATE INDEX idx_users_status ON users(status);
+
+-- 为usermanagements表创建索引
+CREATE INDEX idx_usermanagements_user_id ON usermanagements(user_id);
+CREATE INDEX idx_usermanagements_role_id ON usermanagements(role_id);
+CREATE INDEX idx_usermanagements_permission_level ON usermanagements(permission_level);
+```
+
+### 3.3 上传部署文件
+
+使用SFTP或SCP上传文件到服务器:
+
+```bash
+# 上传WAR文件
+scp target\DL.war user@your-server:/opt/tomcat/webapps/
+
+# 上传索引脚本(用于备份)
+scp CREATE_OPTIMIZATION_INDEXES.sql user@your-server:/opt/tomcat/
+```
+
+### 3.4 服务器部署操作
+
+登录服务器后执行:
+
+```bash
+# 1. 停止Tomcat
+cd /opt/tomcat/bin
+./shutdown.sh
+
+# 2. 等待Tomcat完全停止(约30秒)
+
+# 3. 备份旧应用
+cp -r /opt/tomcat/webapps/DL /opt/tomcat/backup/
+
+# 4. 删除旧部署文件
+rm -rf /opt/tomcat/webapps/DL*
+
+# 5. 确保权限正确
+chown -R tomcat:tomcat /opt/tomcat/webapps/
+chmod -R 755 /opt/tomcat/webapps/
+
+# 6. 启动Tomcat
+./startup.sh
+
+# 7. 监控部署日志
+tail -f /opt/tomcat/logs/catalina.out
+```
+
+## 四、部署后验证
+
+### 4.1 功能验证
+- **访问应用**: `http://your-server-ip:8080/DL`
+- **登录验证**: 确认可以正常登录
+- **数据操作**: 验证增删改查功能正常
+
+### 4.2 性能优化验证
+
+#### 分页功能验证
+- 访问负责人管理页面
+- 确认列表显示已启用分页
+- 验证翻页功能正常工作
+- 检查数据加载速度是否提升
+
+#### SQL查询性能验证
+- 执行常用查询操作
+- 确认响应时间明显改善
+- 监控数据库慢查询日志
+
+#### 缓存效果验证
+- 连续访问相同数据页面
+- 确认第二次及后续访问速度更快
+
+## 五、回滚方案
+
+如遇部署问题,请按以下步骤回滚:
+
+```bash
+# 1. 停止Tomcat
+cd /opt/tomcat/bin
+./shutdown.sh
+
+# 2. 删除新部署文件
+rm -rf /opt/tomcat/webapps/DL*
+
+# 3. 恢复备份
+cp -r /opt/tomcat/backup/DL /opt/tomcat/webapps/
+
+# 4. 启动Tomcat
+./startup.sh
+```
+
+## 六、批处理部署脚本
+
+项目中提供了Windows批处理脚本`deploy_with_optimization.bat`,可以帮助准备部署文件。在项目根目录执行:
+
+```bash
+# 运行批处理脚本
+.\deploy_with_optimization.bat
+```
+
+## 七、注意事项
+
+1. **备份**: 部署前务必备份应用数据和数据库
+2. **维护窗口**: 选择低流量时段进行部署
+3. **索引优化**: 必须执行数据库索引创建脚本
+4. **性能监控**: 部署后持续监控系统性能
+5. **日志检查**: 定期检查应用日志,及时发现问题
+6. **权限问题**: 确保Tomcat用户对所有必要目录有正确权限
+
+## 八、相关文档
+
+- **性能优化详细说明**: `PERFORMANCE_OPTIMIZATION_GUIDE.md`
+- **Mapper XML部署指南**: `MAPPER_XML_DEPLOYMENT_GUIDE.txt`
+- **数据库索引脚本**: `CREATE_OPTIMIZATION_INDEXES.sql`
+
+---
+
+> 部署完成后,请务必执行性能优化验证步骤,确保所有优化措施生效。
\ No newline at end of file
diff --git a/MAPPER_SERVICE_UPDATE_GUIDE.txt b/MAPPER_SERVICE_UPDATE_GUIDE.txt
new file mode 100644
index 0000000..4af069c
--- /dev/null
+++ b/MAPPER_SERVICE_UPDATE_GUIDE.txt
@@ -0,0 +1,146 @@
+# Mapper和Service代码更新部署指南
+
+## 构建状态确认
+
+✅ 所有Mapper和Service Java文件已成功编译为class文件
+
+### Mapper文件(最后编译时间:2025/11/6 13:50)
+- 位置:`target\classes\com\example\web\mapper`
+- 文件数量:20个class文件
+- 包含:Cart_itemsMapper、EnterpriseMapper、ManagersMapper等所有必要的Mapper接口实现
+
+### Service文件(最后编译时间:2025/11/6 13:50)
+- 位置:`target\classes\com\example\web\service`
+- 文件数量:11个class文件
+- 包含:CustomerService、EnterpriseService、LoginService等所有Service实现类
+
+## 部署方案
+
+### 方案一:完整WAR包部署(推荐)
+这种方法最安全、最可靠,确保所有组件版本一致。
+
+1. **准备WAR文件**
+ ```bash
+ # 确保WAR文件已生成
+ ls -la target/DL.war
+ ```
+
+2. **上传WAR文件到服务器**
+ ```bash
+ # 使用SCP上传文件
+ scp target/DL.war user@server:/path/to/tomcat/webapps/
+ ```
+
+3. **设置文件权限**
+ ```bash
+ # 在服务器上执行
+ sudo chown tomcat:tomcat /path/to/tomcat/webapps/DL.war
+ sudo chmod 644 /path/to/tomcat/webapps/DL.war
+ ```
+
+4. **重启Tomcat服务**
+ ```bash
+ # 在服务器上执行
+ sudo systemctl restart tomcat
+ # 或者
+ sudo service tomcat restart
+ # 或者直接使用Tomcat的脚本
+ /path/to/tomcat/bin/shutdown.sh
+ /path/to/tomcat/bin/startup.sh
+ ```
+
+### 方案二:仅更新Mapper和Service的class文件(风险较高)
+如果只修改了Mapper和Service代码,可以只更新这些class文件,但要注意版本兼容性问题。
+
+1. **在服务器上定位目标目录**
+ ```bash
+ # 在服务器上执行,找到应用部署目录
+ cd /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/
+ ```
+
+2. **备份当前文件**
+ ```bash
+ # 在服务器上执行
+ mkdir -p ~/backup/mapper ~/backup/service
+ cp -r mapper/* ~/backup/mapper/
+ cp -r service/* ~/backup/service/
+ ```
+
+3. **上传新的class文件**
+ ```bash
+ # 上传mapper文件
+ scp target/classes/com/example/web/mapper/*.class user@server:/path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/mapper/
+
+ # 上传service文件
+ scp target/classes/com/example/web/service/*.class user@server:/path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/service/
+ ```
+
+4. **设置文件权限**
+ ```bash
+ # 在服务器上执行
+ sudo chown -R tomcat:tomcat /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/mapper/
+ sudo chown -R tomcat:tomcat /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/service/
+ sudo chmod 644 /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/mapper/*.class
+ sudo chmod 644 /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/service/*.class
+ ```
+
+5. **重载应用(可选)**
+ - 方法1:重启Tomcat(最可靠)
+ ```bash
+ sudo systemctl restart tomcat
+ ```
+ - 方法2:使用Tomcat Manager或JMX热重载(风险较高)
+
+## 验证部署
+
+1. **检查Tomcat日志**
+ ```bash
+ # 在服务器上执行
+ tail -f /path/to/tomcat/logs/catalina.out
+ ```
+
+2. **测试应用功能**
+ - 访问应用的关键功能
+ - 执行涉及更新的Mapper和Service的操作
+
+## 回滚方案
+
+如果遇到问题,按照以下步骤回滚:
+
+1. **方案一回滚**
+ ```bash
+ # 在服务器上执行
+ sudo rm -f /path/to/tomcat/webapps/DL.war
+ sudo rm -rf /path/to/tomcat/webapps/DL/
+ # 上传之前的备份WAR文件
+ scp backup/DL.war user@server:/path/to/tomcat/webapps/
+ sudo chown tomcat:tomcat /path/to/tomcat/webapps/DL.war
+ sudo systemctl restart tomcat
+ ```
+
+2. **方案二回滚**
+ ```bash
+ # 在服务器上执行
+ cp -r ~/backup/mapper/* /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/mapper/
+ cp -r ~/backup/service/* /path/to/tomcat/webapps/DL/WEB-INF/classes/com/example/web/service/
+ sudo systemctl restart tomcat
+ ```
+
+## 注意事项
+
+1. **版本兼容性**:确保Mapper和Service的修改与其他组件兼容
+2. **事务一致性**:特别注意涉及多个Mapper的事务操作
+3. **数据库变更**:如果Mapper修改涉及数据库结构变更,请先执行数据库迁移
+4. **缓存清理**:如有必要,清除相关缓存
+5. **生产环境建议**:在生产环境中,强烈推荐使用方案一进行完整部署
+
+## 后续维护建议
+
+1. **建立部署文档**:记录每次部署的变更内容
+2. **制定回滚计划**:为每次更新准备回滚方案
+3. **监控应用性能**:部署后密切关注应用性能指标
+4. **测试完整性**:执行完整的功能测试套件
+
+---
+
+此指南由自动化工具生成,最后更新时间:2025/11/6 13:51
\ No newline at end of file
diff --git a/MAPPER_XML_DEPLOYMENT_GUIDE.txt b/MAPPER_XML_DEPLOYMENT_GUIDE.txt
new file mode 100644
index 0000000..bf9aa1a
--- /dev/null
+++ b/MAPPER_XML_DEPLOYMENT_GUIDE.txt
@@ -0,0 +1,163 @@
+# MyBatis Mapper XML文件部署指南(含性能优化)
+
+## 文件状态确认
+
+✅ 所有MyBatis Mapper XML映射文件已成功复制到构建目录
+
+### Mapper XML文件(最后修改时间与源代码一致)
+- 源文件位置:`src\main\resources\mapper`
+- 构建后位置:`target\classes\mapper`
+- 文件数量:16个XML文件
+- 包含:Cart_itemsMapper.xml、EnterpriseMapper.xml、ManagersMapper.xml等所有必要的MyBatis映射文件
+
+## 部署方案
+
+### 方案一:完整WAR包部署(推荐)
+这种方法最安全、最可靠,确保所有组件版本一致。
+
+1. **准备WAR文件**
+ ```bash
+ # 确保WAR文件已生成
+ ls -la target/DL.war
+ ```
+
+2. **上传WAR文件到服务器**
+ ```bash
+ # 使用SCP上传文件
+ scp target/DL.war user@server:/path/to/tomcat/webapps/
+ ```
+
+3. **设置文件权限**
+ ```bash
+ # 在服务器上执行
+ sudo chown tomcat:tomcat /path/to/tomcat/webapps/DL.war
+ sudo chmod 644 /path/to/tomcat/webapps/DL.war
+ ```
+
+4. **重启Tomcat服务**
+ ```bash
+ # 在服务器上执行
+ sudo systemctl restart tomcat
+ # 或者
+ sudo service tomcat restart
+ # 或者直接使用Tomcat的脚本
+ /path/to/tomcat/bin/shutdown.sh
+ /path/to/tomcat/bin/startup.sh
+ ```
+
+### 方案二:仅更新Mapper XML文件(中等风险)
+如果只修改了Mapper XML文件,可以只更新这些文件,但要注意版本兼容性问题。
+
+1. **在服务器上定位目标目录**
+ ```bash
+ # 在服务器上执行,找到应用部署目录
+ cd /path/to/tomcat/webapps/DL/WEB-INF/classes/mapper/
+ ```
+
+2. **备份当前文件**
+ ```bash
+ # 在服务器上执行
+ mkdir -p ~/backup/mapper_xml
+ cp -r * ~/backup/mapper_xml/
+ ```
+
+3. **上传新的XML文件**
+ ```bash
+ # 上传所有XML文件
+ scp target/classes/mapper/*.xml user@server:/path/to/tomcat/webapps/DL/WEB-INF/classes/mapper/
+ ```
+
+4. **设置文件权限**
+ ```bash
+ # 在服务器上执行
+ sudo chown -R tomcat:tomcat /path/to/tomcat/webapps/DL/WEB-INF/classes/mapper/
+ sudo chmod 644 /path/to/tomcat/webapps/DL/WEB-INF/classes/mapper/*.xml
+ ```
+
+5. **重载应用**
+ - 方法1:重启Tomcat(最可靠)
+ ```bash
+ sudo systemctl restart tomcat
+ ```
+ - 方法2:使用Tomcat Manager重新加载应用(较快)
+ ```bash
+ # 使用curl命令重新加载应用
+ curl -u username:password "http://localhost:8080/manager/text/reload?path=/DL"
+ ```
+
+## 性能优化内容
+
+1. **SQL查询优化**:
+ - 将SELECT *查询替换为显式字段列表
+ - 移除不必要的连接操作
+
+2. **分页功能**:
+ - 添加selectAllManagersWithPagination方法实现分页查询
+ - 新增getManagersCount方法获取总数
+
+3. **二级缓存配置**:
+ - 为ManagersMapper添加LRU二级缓存
+
+4. **数据库索引**:
+ - 为关键字段创建索引,提升查询性能
+ - 详细索引创建脚本请参考CREATE_OPTIMIZATION_INDEXES.sql
+
+## 验证部署
+
+1. **检查Tomcat日志**
+ ```bash
+ # 在服务器上执行
+ tail -f /path/to/tomcat/logs/catalina.out
+ ```
+
+2. **测试数据库操作**
+ - 访问负责人管理页面,验证分页功能是否正常
+ - 测试数据查询操作,确认响应速度提升
+ - 检查应用日志,确保没有错误
+ - 监控数据库性能,确认索引正常使用
+
+## 回滚方案
+
+如果遇到问题,按照以下步骤回滚:
+
+1. **方案一回滚**
+ ```bash
+ # 在服务器上执行
+ sudo rm -f /path/to/tomcat/webapps/DL.war
+ sudo rm -rf /path/to/tomcat/webapps/DL/
+ # 上传之前的备份WAR文件
+ scp backup/DL.war user@server:/path/to/tomcat/webapps/
+ sudo chown tomcat:tomcat /path/to/tomcat/webapps/DL.war
+ sudo systemctl restart tomcat
+ ```
+
+2. **方案二回滚**
+ ```bash
+ # 在服务器上执行
+ cp -r ~/backup/mapper_xml/* /path/to/tomcat/webapps/DL/WEB-INF/classes/mapper/
+ sudo systemctl restart tomcat
+ ```
+
+## 注意事项
+
+1. **版本兼容性**:确保Mapper XML的修改与对应的Java接口兼容
+2. **SQL语法检查**:部署前确认XML中的SQL语句语法正确
+3. **数据库结构**:如果SQL修改涉及表结构变更,请先执行数据库迁移
+4. **缓存清理**:MyBatis可能缓存映射文件,重启Tomcat可以确保清除缓存
+5. **事务一致性**:特别注意涉及多个Mapper的事务操作
+6. **参数类型**:确保XML中定义的参数类型与Java代码中的参数类型匹配
+7. **数据库备份**:确保在部署前备份数据库
+8. **索引优化**:部署新版本后务必执行数据库索引优化脚本
+9. **分页验证**:验证分页功能是否正常工作
+10. **性能监控**:持续监控数据库查询性能,必要时进行进一步优化
+
+## 后续维护建议
+
+1. **版本控制**:对Mapper XML文件进行版本控制,记录每次变更
+2. **自动化部署**:考虑使用CI/CD工具自动化部署过程
+3. **监控查询性能**:部署后监控查询性能,特别是对于复杂的SQL语句
+4. **备份策略**:建立定期备份策略,包括数据库和应用配置
+
+---
+
+此指南由自动化工具生成,最后更新时间:2025/11/6
\ No newline at end of file
diff --git a/PERFORMANCE_OPTIMIZATION_GUIDE.md b/PERFORMANCE_OPTIMIZATION_GUIDE.md
new file mode 100644
index 0000000..389fc76
--- /dev/null
+++ b/PERFORMANCE_OPTIMIZATION_GUIDE.md
@@ -0,0 +1,280 @@
+# 数据库性能优化指南
+
+## 问题分析
+
+根据对Mapper XML文件的检查,发现以下可能导致数据返回慢的主要问题:
+
+### 1. 使用 SELECT * 查询所有字段
+- **问题**:`SELECT *` 查询会返回表中的所有列,增加网络传输量和处理时间
+- **影响文件**:ManagersMapper.xml中的多个查询
+
+### 2. 复杂的JOIN和嵌套WHERE条件
+- **问题**:复杂的JOIN操作和多层嵌套条件会增加数据库解析和执行时间
+- **影响文件**:UsersMapper.xml中的`getAuthorizedCustomers`和`getAuthorizedUserIds`查询
+
+### 3. 可能缺少必要的索引
+- **问题**:频繁用于查询条件的字段可能缺少索引,导致全表扫描
+- **影响字段**:userId, phoneNumber, type, level, managerId等
+
+### 4. 未使用分页查询
+- **问题**:查询大量数据时未使用分页,一次性返回过多数据
+- **影响文件**:selectAllManagers等查询
+
+## 优化方案
+
+### 1. 优化SQL查询语句
+
+#### 1.1 替换 SELECT * 为具体字段
+
+**修改前** (ManagersMapper.xml):
+```xml
+
+```
+
+**修改后**:
+```xml
+
+```
+
+对其他使用 `SELECT *` 的查询也进行类似修改。
+
+#### 1.2 优化复杂的JOIN查询
+
+**修改建议** (UsersMapper.xml):
+- 将复杂的嵌套条件拆分为更简单的部分
+- 使用子查询代替部分复杂JOIN
+- 考虑使用临时表缓存中间结果
+
+#### 1.3 添加分页查询
+
+**修改前**:
+```xml
+
+```
+
+**修改后**:
+```xml
+
+```
+
+同时在Mapper接口中添加对应的方法。
+
+### 2. 添加必要的数据库索引
+
+建议在以下字段上添加索引:
+
+```sql
+-- 在users表上添加索引
+CREATE INDEX idx_users_userId ON users(userId);
+CREATE INDEX idx_users_phoneNumber ON users(phoneNumber);
+CREATE INDEX idx_users_type ON users(type);
+CREATE INDEX idx_users_level ON users(level);
+CREATE INDEX idx_users_created_at ON users(created_at);
+
+-- 在managers表上添加索引
+CREATE INDEX idx_managers_id ON managers(id);
+CREATE INDEX idx_managers_userName ON managers(userName);
+CREATE INDEX idx_managers_managerId ON managers(managerId);
+
+-- 在usermanagements表上添加索引
+CREATE INDEX idx_usermanagements_userId ON usermanagements(userId);
+CREATE INDEX idx_usermanagements_managerId ON usermanagements(managerId);
+CREATE INDEX idx_usermanagements_userName ON usermanagements(userName);
+CREATE INDEX idx_usermanagements_organization ON usermanagements(organization);
+CREATE INDEX idx_usermanagements_managerdepartment ON usermanagements(managerdepartment);
+```
+
+### 3. 添加缓存机制
+
+#### 3.1 在MyBatis中添加二级缓存
+
+在Mapper XML文件中添加缓存配置:
+
+```xml
+
+
+
+
+
+
+
+```
+
+#### 3.2 在Service层添加本地缓存
+
+在Service类中使用Guava Cache或Caffeine等本地缓存库。
+
+### 4. 优化结果集映射
+
+#### 4.1 优化ResultMap定义
+
+确保ResultMap只映射必要的字段,避免不必要的映射。
+
+#### 4.2 使用Constructor Args映射
+
+对于频繁使用的DTO,可以考虑使用构造函数参数映射,提高性能。
+
+## 具体优化实施
+
+### 优化ManagersMapper.xml
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO managers (
+ id, managerId, managercompany, managerdepartment,
+ organization, role, root, created_at, updated_at,
+ userName, assistant
+ ) VALUES (
+ #{id}, #{managerId}, #{managercompany}, #{managerdepartment},
+ #{organization}, #{role}, #{root}, #{created_at}, #{updated_at},
+ #{userName}, #{assistant}
+ )
+
+
+
+
+ UPDATE managers
+ SET
+ managercompany = #{managercompany},
+ managerdepartment = #{managerdepartment},
+ organization = #{organization},
+ role = #{role},
+ userName = #{userName},
+ assistant = #{assistant},
+ updated_at = #{updated_at}
+ WHERE id = #{id}
+
+
+```
+
+### 优化UsersMapper接口添加分页方法
+
+在UsersMapper.java中添加分页查询方法:
+
+```java
+// 分页查询授权客户
+List getAuthorizedCustomersWithPagination(Map params);
+
+// 获取授权客户总数
+int getAuthorizedCustomersCount(Map params);
+```
+
+## 验证优化效果
+
+优化后,建议通过以下方式验证性能改进:
+
+1. **使用EXPLAIN分析SQL执行计划**
+ ```sql
+ EXPLAIN SELECT manager_id, id, managerId, managercompany, managerdepartment,
+ organization, role, root, userName, assistant
+ FROM managers WHERE userName = 'someName';
+ ```
+
+2. **添加性能监控日志**
+ 在Service层添加方法执行时间记录。
+
+3. **压力测试**
+ 使用JMeter等工具进行压力测试,比较优化前后的响应时间。
+
+## 额外建议
+
+1. **考虑读写分离**
+ 对于高并发场景,考虑实现数据库读写分离。
+
+2. **使用数据库连接池**
+ 确保使用高效的连接池管理数据库连接。
+
+3. **定期清理和优化数据库**
+ 定期执行VACUUM(PostgreSQL)或OPTIMIZE TABLE(MySQL)等操作。
+
+4. **考虑使用NoSQL缓存热点数据**
+ 对于频繁访问的数据,可以考虑使用Redis等NoSQL数据库进行缓存。
+
+---
+
+此优化指南由自动化工具生成,建议根据实际情况进行调整和测试。
\ No newline at end of file
diff --git a/TOMCAT_DEPLOYMENT_STEPS.txt b/TOMCAT_DEPLOYMENT_STEPS.txt
new file mode 100644
index 0000000..dfc4365
--- /dev/null
+++ b/TOMCAT_DEPLOYMENT_STEPS.txt
@@ -0,0 +1,118 @@
+# TOMCAT 10.1.48 DEPLOYMENT STEPS
+
+## PREREQUISITES
+1. Tomcat 10.1.48 installed at /opt/tomcat
+2. JDK 17 or higher installed on the server
+3. Generated DL.war file in target directory
+
+## DEPLOYMENT STEPS
+
+### 1. Prepare Deployment File
+The DL.war file has been successfully created and is ready for deployment.
+
+### 2. Upload WAR File to Server
+
+```bash
+# From Windows using WinSCP or FileZilla:
+# - Connect to your server
+# - Upload d:\java\project\web(8)\web\target\DL.war to /opt/tomcat/webapps/
+
+# Or from command line using scp (open Command Prompt as Administrator):
+scp "d:\java\project\web(8)\web\target\DL.war" user@your-server:/opt/tomcat/webapps/
+```
+
+### 3. Set Permissions on Server
+
+Connect to your server via SSH and run:
+
+```bash
+cd /opt/tomcat
+sudo chown -R tomcat:tomcat webapps/
+sudo chmod -R 755 webapps/
+```
+
+### 4. Configure Tomcat (Recommended)
+
+```bash
+# Edit context.xml to prevent resource locking issues
+sudo nano /opt/tomcat/conf/context.xml
+
+# Add antiResourceLocking and antiJARLocking attributes to Context element
+
+
+
+
+# Save and exit (Ctrl+O, Enter, Ctrl+X)
+
+# Create setenv.sh for memory optimization
+sudo nano /opt/tomcat/bin/setenv.sh
+
+# Add these lines:
+#!/bin/bash
+JAVA_OPTS="-Xms512m -Xmx1024m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m"
+JAVA_OPTS="$JAVA_OPTS --add-opens=java.base/java.lang=ALL-UNNAMED"
+
+# Save and exit
+
+# Make it executable
+sudo chmod +x /opt/tomcat/bin/setenv.sh
+```
+
+### 5. Restart Tomcat
+
+```bash
+cd /opt/tomcat/bin
+
+# Stop Tomcat
+sudo ./shutdown.sh
+
+# Wait for Tomcat to stop completely
+sleep 30
+
+# Start Tomcat
+sudo ./startup.sh
+```
+
+### 6. Verify Deployment
+
+```bash
+# Monitor Tomcat logs
+tail -f /opt/tomcat/logs/catalina.out
+
+# Access the application in a browser
+# http://your-server-ip:8080/DL
+# http://your-server-ip:8080/DL/loginmm.html (for login page)
+```
+
+## TROUBLESHOOTING
+
+1. **Application not accessible**:
+ - Check if Tomcat is running: `ps aux | grep tomcat`
+ - Verify WAR file was deployed: `ls -la /opt/tomcat/webapps/`
+ - Look for errors in logs: `cat /opt/tomcat/logs/catalina.out`
+
+2. **Database connection issues**:
+ - Ensure database server is reachable from Tomcat server
+ - Verify database credentials in application.yaml
+
+3. **Port conflicts**:
+ - If port 8080 is in use, change it in server.xml:
+ `sudo nano /opt/tomcat/conf/server.xml`
+ Find and modify: ` nul
+if %errorlevel% neq 0 (
+ echo 错误:重命名WAR文件失败
+ pause
+ exit /b 1
+)
+echo 已将WAR文件重命名为:%DEPLOY_WAR%
+
+rem 5. 复制索引脚本到备份目录
+if exist "%INDEX_SCRIPT%" (
+ copy "%INDEX_SCRIPT%" "%BACKUP_DIR%\%INDEX_SCRIPT%" > nul
+ echo 已复制数据库索引脚本到备份目录
+)
+
+rem 6. 提示数据库索引优化步骤
+echo.
+echo ====================================
+echo 数据库索引优化(重要)
+echo ====================================
+echo 请在数据库服务器上执行以下操作:
+echo 1. 登录数据库服务器
+echo 2. 执行索引创建脚本:
+echo source %BACKUP_DIR%\%INDEX_SCRIPT%
+echo 或直接复制脚本内容执行
+
+echo.
+echo ====================================
+echo 部署准备完成!
+echo ====================================
+echo 部署文件:%DEPLOY_WAR%
+echo 备份位置:%BACKUP_DIR%
+echo.
+echo 下一步操作:
+echo 1. 上传 %DEPLOY_WAR% 到Tomcat服务器的webapps目录
+echo 2. 在数据库服务器上执行索引优化脚本
+echo 3. 重启Tomcat服务器
+echo 4. 验证性能优化效果
+echo.
+pause
\ No newline at end of file
diff --git a/mvnw b/mvnw
new file mode 100644
index 0000000..bd8896b
--- /dev/null
+++ b/mvnw
@@ -0,0 +1,295 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Apache Maven Wrapper startup batch script, version 3.3.4
+#
+# Optional ENV vars
+# -----------------
+# JAVA_HOME - location of a JDK home dir, required when download maven via java source
+# MVNW_REPOURL - repo url base for downloading maven distribution
+# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
+# ----------------------------------------------------------------------------
+
+set -euf
+[ "${MVNW_VERBOSE-}" != debug ] || set -x
+
+# OS specific support.
+native_path() { printf %s\\n "$1"; }
+case "$(uname)" in
+CYGWIN* | MINGW*)
+ [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
+ native_path() { cygpath --path --windows "$1"; }
+ ;;
+esac
+
+# set JAVACMD and JAVACCMD
+set_java_home() {
+ # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
+ if [ -n "${JAVA_HOME-}" ]; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ]; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACCMD="$JAVA_HOME/jre/sh/javac"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ JAVACCMD="$JAVA_HOME/bin/javac"
+
+ if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
+ echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
+ echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
+ return 1
+ fi
+ fi
+ else
+ JAVACMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v java
+ )" || :
+ JAVACCMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v javac
+ )" || :
+
+ if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
+ echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
+ return 1
+ fi
+ fi
+}
+
+# hash string like Java String::hashCode
+hash_string() {
+ str="${1:-}" h=0
+ while [ -n "$str" ]; do
+ char="${str%"${str#?}"}"
+ h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
+ str="${str#?}"
+ done
+ printf %x\\n $h
+}
+
+verbose() { :; }
+[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
+
+die() {
+ printf %s\\n "$1" >&2
+ exit 1
+}
+
+trim() {
+ # MWRAPPER-139:
+ # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
+ # Needed for removing poorly interpreted newline sequences when running in more
+ # exotic environments such as mingw bash on Windows.
+ printf "%s" "${1}" | tr -d '[:space:]'
+}
+
+scriptDir="$(dirname "$0")"
+scriptName="$(basename "$0")"
+
+# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
+while IFS="=" read -r key value; do
+ case "${key-}" in
+ distributionUrl) distributionUrl=$(trim "${value-}") ;;
+ distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
+ esac
+done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
+[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
+
+case "${distributionUrl##*/}" in
+maven-mvnd-*bin.*)
+ MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
+ case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
+ *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
+ :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
+ :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
+ :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
+ *)
+ echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
+ distributionPlatform=linux-amd64
+ ;;
+ esac
+ distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
+ ;;
+maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
+*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
+esac
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
+distributionUrlName="${distributionUrl##*/}"
+distributionUrlNameMain="${distributionUrlName%.*}"
+distributionUrlNameMain="${distributionUrlNameMain%-bin}"
+MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
+MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
+
+exec_maven() {
+ unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
+ exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
+}
+
+if [ -d "$MAVEN_HOME" ]; then
+ verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ exec_maven "$@"
+fi
+
+case "${distributionUrl-}" in
+*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
+*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
+esac
+
+# prepare tmp dir
+if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
+ clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
+ trap clean HUP INT TERM EXIT
+else
+ die "cannot create temp dir"
+fi
+
+mkdir -p -- "${MAVEN_HOME%/*}"
+
+# Download and Install Apache Maven
+verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+verbose "Downloading from: $distributionUrl"
+verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+# select .zip or .tar.gz
+if ! command -v unzip >/dev/null; then
+ distributionUrl="${distributionUrl%.zip}.tar.gz"
+ distributionUrlName="${distributionUrl##*/}"
+fi
+
+# verbose opt
+__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
+[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
+
+# normalize http auth
+case "${MVNW_PASSWORD:+has-password}" in
+'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+esac
+
+if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
+ verbose "Found wget ... using wget"
+ wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
+elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
+ verbose "Found curl ... using curl"
+ curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
+elif set_java_home; then
+ verbose "Falling back to use Java to download"
+ javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
+ targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
+ cat >"$javaSource" <<-END
+ public class Downloader extends java.net.Authenticator
+ {
+ protected java.net.PasswordAuthentication getPasswordAuthentication()
+ {
+ return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
+ }
+ public static void main( String[] args ) throws Exception
+ {
+ setDefault( new Downloader() );
+ java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
+ }
+ }
+ END
+ # For Cygwin/MinGW, switch paths to Windows format before running javac and java
+ verbose " - Compiling Downloader.java ..."
+ "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
+ verbose " - Running Downloader.java ..."
+ "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
+fi
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+if [ -n "${distributionSha256Sum-}" ]; then
+ distributionSha256Result=false
+ if [ "$MVN_CMD" = mvnd.sh ]; then
+ echo "Checksum validation is not supported for maven-mvnd." >&2
+ echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ elif command -v sha256sum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ elif command -v shasum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ else
+ echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
+ echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ fi
+ if [ $distributionSha256Result = false ]; then
+ echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
+ echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
+ exit 1
+ fi
+fi
+
+# unzip and move
+if command -v unzip >/dev/null; then
+ unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
+else
+ tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
+fi
+
+# Find the actual extracted directory name (handles snapshots where filename != directory name)
+actualDistributionDir=""
+
+# First try the expected directory name (for regular distributions)
+if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
+ if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
+ actualDistributionDir="$distributionUrlNameMain"
+ fi
+fi
+
+# If not found, search for any directory with the Maven executable (for snapshots)
+if [ -z "$actualDistributionDir" ]; then
+ # enable globbing to iterate over items
+ set +f
+ for dir in "$TMP_DOWNLOAD_DIR"/*; do
+ if [ -d "$dir" ]; then
+ if [ -f "$dir/bin/$MVN_CMD" ]; then
+ actualDistributionDir="$(basename "$dir")"
+ break
+ fi
+ fi
+ done
+ set -f
+fi
+
+if [ -z "$actualDistributionDir" ]; then
+ verbose "Contents of $TMP_DOWNLOAD_DIR:"
+ verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
+ die "Could not find Maven distribution directory in extracted archive"
+fi
+
+verbose "Found extracted Maven distribution directory: $actualDistributionDir"
+printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
+mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
+
+clean || :
+exec_maven "$@"
diff --git a/mvnw.cmd b/mvnw.cmd
new file mode 100644
index 0000000..92450f9
--- /dev/null
+++ b/mvnw.cmd
@@ -0,0 +1,189 @@
+<# : batch portion
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Apache Maven Wrapper startup batch script, version 3.3.4
+@REM
+@REM Optional ENV vars
+@REM MVNW_REPOURL - repo url base for downloading maven distribution
+@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
+@REM ----------------------------------------------------------------------------
+
+@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
+@SET __MVNW_CMD__=
+@SET __MVNW_ERROR__=
+@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
+@SET PSModulePath=
+@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
+ IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
+)
+@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
+@SET __MVNW_PSMODULEP_SAVE=
+@SET __MVNW_ARG0_NAME__=
+@SET MVNW_USERNAME=
+@SET MVNW_PASSWORD=
+@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
+@echo Cannot start maven from wrapper >&2 && exit /b 1
+@GOTO :EOF
+: end batch / begin powershell #>
+
+$ErrorActionPreference = "Stop"
+if ($env:MVNW_VERBOSE -eq "true") {
+ $VerbosePreference = "Continue"
+}
+
+# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
+$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
+if (!$distributionUrl) {
+ Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
+}
+
+switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
+ "maven-mvnd-*" {
+ $USE_MVND = $true
+ $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
+ $MVN_CMD = "mvnd.cmd"
+ break
+ }
+ default {
+ $USE_MVND = $false
+ $MVN_CMD = $script -replace '^mvnw','mvn'
+ break
+ }
+}
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+if ($env:MVNW_REPOURL) {
+ $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
+ $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
+}
+$distributionUrlName = $distributionUrl -replace '^.*/',''
+$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
+
+$MAVEN_M2_PATH = "$HOME/.m2"
+if ($env:MAVEN_USER_HOME) {
+ $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
+}
+
+if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
+ New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
+}
+
+$MAVEN_WRAPPER_DISTS = $null
+if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
+ $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
+} else {
+ $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
+}
+
+$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
+$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
+$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
+
+if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
+ Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
+ exit $?
+}
+
+if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
+ Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
+}
+
+# prepare tmp dir
+$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
+$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
+$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
+trap {
+ if ($TMP_DOWNLOAD_DIR.Exists) {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+ }
+}
+
+New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
+
+# Download and Install Apache Maven
+Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+Write-Verbose "Downloading from: $distributionUrl"
+Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+$webclient = New-Object System.Net.WebClient
+if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
+ $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
+}
+[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
+if ($distributionSha256Sum) {
+ if ($USE_MVND) {
+ Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
+ }
+ Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
+ if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
+ Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
+ }
+}
+
+# unzip and move
+Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
+
+# Find the actual extracted directory name (handles snapshots where filename != directory name)
+$actualDistributionDir = ""
+
+# First try the expected directory name (for regular distributions)
+$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
+$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
+if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
+ $actualDistributionDir = $distributionUrlNameMain
+}
+
+# If not found, search for any directory with the Maven executable (for snapshots)
+if (!$actualDistributionDir) {
+ Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
+ $testPath = Join-Path $_.FullName "bin/$MVN_CMD"
+ if (Test-Path -Path $testPath -PathType Leaf) {
+ $actualDistributionDir = $_.Name
+ }
+ }
+}
+
+if (!$actualDistributionDir) {
+ Write-Error "Could not find Maven distribution directory in extracted archive"
+}
+
+Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
+Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
+try {
+ Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
+} catch {
+ if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
+ Write-Error "fail to move MAVEN_HOME"
+ }
+} finally {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+}
+
+Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..74a8a9b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,153 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.4.10
+
+
+ com.example
+ web
+ 0.0.1-SNAPSHOT
+ war
+ web
+ web
+
+
+ 17
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ me.paulschwarz
+ spring-dotenv
+ 4.0.0
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.24
+ true
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-tomcat
+ provided
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 3.0.4
+
+
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ 1.2.20
+
+
+
+
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.1.0
+
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+
+ me.paulschwarz
+ spring-dotenv
+ 4.0.0
+
+
+
+ org.hibernate.validator
+ hibernate-validator
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 3.4.10
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/example/web/ServletInitializer.java b/src/main/java/com/example/web/ServletInitializer.java
new file mode 100644
index 0000000..d1354ab
--- /dev/null
+++ b/src/main/java/com/example/web/ServletInitializer.java
@@ -0,0 +1,13 @@
+package com.example.web;
+
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+
+public class ServletInitializer extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(WebApplication.class);
+ }
+
+}
diff --git a/src/main/java/com/example/web/WebApplication.java b/src/main/java/com/example/web/WebApplication.java
new file mode 100644
index 0000000..67d0c8a
--- /dev/null
+++ b/src/main/java/com/example/web/WebApplication.java
@@ -0,0 +1,18 @@
+package com.example.web;
+
+import me.paulschwarz.springdotenv.DotenvPropertySource;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@SpringBootApplication
+@MapperScan("com.example.web.mapper")
+@EnableScheduling//定时任务
+/*@PropertySource(value = "classpath:.env", factory = DotenvPropertySource.class)*/
+public class WebApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(WebApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/web/annotation/DataSource.java b/src/main/java/com/example/web/annotation/DataSource.java
new file mode 100644
index 0000000..c34eaa9
--- /dev/null
+++ b/src/main/java/com/example/web/annotation/DataSource.java
@@ -0,0 +1,14 @@
+// DataSource.java
+package com.example.web.annotation;
+
+import java.lang.annotation.*;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface DataSource {
+ // 数据源名称,对应配置中的"primary"和"wechat"
+ String value() default "primary";
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/web/aspect/DataSourceAspect.java b/src/main/java/com/example/web/aspect/DataSourceAspect.java
new file mode 100644
index 0000000..ac2275e
--- /dev/null
+++ b/src/main/java/com/example/web/aspect/DataSourceAspect.java
@@ -0,0 +1,50 @@
+package com.example.web.aspect;
+
+import com.example.web.annotation.DataSource;
+import com.example.web.config.DynamicDataSource;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+
+@Aspect
+@Component
+@Order(1) // 设置Order为1,确保在事务切面之前执行
+public class DataSourceAspect {
+
+ // 拦截所有标注了 @DataSource 注解的类或方法
+ @Pointcut("@annotation(com.example.web.annotation.DataSource) || @within(com.example.web.annotation.DataSource)")
+ public void dataSourcePointCut() {}
+
+ @Around("dataSourcePointCut()")
+ public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
+ // 获取目标方法和类上的 @DataSource 注解
+ MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+ Method method = signature.getMethod();
+ DataSource methodAnnotation = method.getAnnotation(DataSource.class);
+ DataSource classAnnotation = AnnotationUtils.findAnnotation(joinPoint.getTarget().getClass(), DataSource.class);
+
+ // 方法注解优先于类注解
+ String dataSourceKey = methodAnnotation != null ? methodAnnotation.value() :
+ (classAnnotation != null ? classAnnotation.value() : "primary");
+
+ try {
+ // 切换数据源
+ DynamicDataSource.setDataSourceKey(dataSourceKey);
+ // 执行目标方法
+ System.out.println("切换到数据源: " + dataSourceKey);
+ return joinPoint.proceed();
+ } finally {
+ // 清除数据源,避免线程池复用导致的问题
+ DynamicDataSource.clearDataSourceKey();
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/web/config/DataSourceConfig.java b/src/main/java/com/example/web/config/DataSourceConfig.java
new file mode 100644
index 0000000..d2f95d8
--- /dev/null
+++ b/src/main/java/com/example/web/config/DataSourceConfig.java
@@ -0,0 +1,42 @@
+package com.example.web.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+public class DataSourceConfig {
+
+ // 主数据源(userlogin)
+ @Bean(name = "primaryDataSource")
+ @ConfigurationProperties(prefix = "spring.datasource.primary")
+ public DataSource primaryDataSource() {
+ return DataSourceBuilder.create().build();
+ }
+
+ // 第二个数据源(wechat_app)
+ @Bean(name = "wechatDataSource")
+ @ConfigurationProperties(prefix = "spring.datasource.wechat")
+ public DataSource wechatDataSource() {
+ return DataSourceBuilder.create().build();
+ }
+
+ // 动态数据源配置
+ @Primary
+ @Bean(name = "dynamicDataSource")
+ public DataSource dynamicDataSource() {
+ DynamicDataSource dynamicDataSource = new DynamicDataSource();
+ dynamicDataSource.setDefaultTargetDataSource(primaryDataSource());
+ Map