2026-03-12 19:49:48 +08:00
|
|
|
|
# Java 后端启动完整指南
|
|
|
|
|
|
|
|
|
|
|
|
## ✅ 环境配置完成
|
|
|
|
|
|
|
|
|
|
|
|
当前系统状态(已完成配置):
|
|
|
|
|
|
- ✅ **Java 17.0.18** (Amazon Corretto) - 通过 SDKMAN 安装
|
|
|
|
|
|
- ✅ **Maven 3.9.13** - 通过 SDKMAN 安装
|
|
|
|
|
|
- ✅ **Python 3.9.6** - 已安装
|
|
|
|
|
|
- ✅ **MySQL 连接器** - 已安装
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 快速启动指南
|
|
|
|
|
|
|
|
|
|
|
|
### 方案 A:使用命令行(推荐)
|
|
|
|
|
|
|
|
|
|
|
|
**步骤:**
|
|
|
|
|
|
|
|
|
|
|
|
1. **加载环境变量**:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
source "$HOME/.sdkman/bin/sdkman-init.sh"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
2. **验证安装**:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
java -version
|
|
|
|
|
|
mvn -version
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
3. **进入项目目录**:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
cd /Users/retirado/Program/ccProgram_0312/reading-platform-java
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
4. **启动后端**:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
mvn spring-boot:run
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**优点**:
|
|
|
|
|
|
- 快速直接,无需额外工具
|
|
|
|
|
|
- 可以看到完整的启动日志
|
|
|
|
|
|
- 便于调试
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
### 方案 B:使用 IntelliJ IDEA(图形界面)
|
|
|
|
|
|
|
|
|
|
|
|
**步骤:**
|
|
|
|
|
|
1. 下载并安装 IntelliJ IDEA Community Edition (免费)
|
|
|
|
|
|
- 下载地址:https://www.jetbrains.com/idea/download/
|
|
|
|
|
|
|
|
|
|
|
|
2. 打开 IntelliJ IDEA
|
|
|
|
|
|
3. 选择 `File` → `Open`
|
|
|
|
|
|
4. 选择目录:`/Users/retirado/Program/ccProgram_0312/reading-platform-java`
|
|
|
|
|
|
5. 等待 IDEA 自动识别项目并下载 Maven 依赖
|
|
|
|
|
|
6. 找到 `src/main/java/com/reading/platform/ReadingPlatformApplication.java`
|
|
|
|
|
|
7. 点击类名旁边的绿色播放按钮 ▶️
|
|
|
|
|
|
|
|
|
|
|
|
**优点**:
|
|
|
|
|
|
- 图形化界面,操作简单
|
|
|
|
|
|
- 内置代码编辑和调试功能
|
|
|
|
|
|
- 无需手动配置环境变量
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 启动成功后的验证
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 检查启动日志
|
|
|
|
|
|
控制台应显示以下内容表示启动成功:
|
|
|
|
|
|
```
|
|
|
|
|
|
Tomcat started on port 8080 (http)
|
|
|
|
|
|
Started ReadingPlatformApplication in X seconds
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 2. 访问 API 文档
|
|
|
|
|
|
```
|
|
|
|
|
|
http://localhost:8080/doc.html
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Knife4j 文档界面提供:
|
|
|
|
|
|
- 完整的 API 列表
|
|
|
|
|
|
- 在线测试功能
|
|
|
|
|
|
- 接口参数说明
|
|
|
|
|
|
|
|
|
|
|
|
### 3. 测试登录接口
|
|
|
|
|
|
|
|
|
|
|
|
**请求示例:**
|
|
|
|
|
|
```bash
|
|
|
|
|
|
curl -X POST http://localhost:8080/api/auth/login \
|
|
|
|
|
|
-H "Content-Type: application/json" \
|
2026-03-14 16:50:54 +08:00
|
|
|
|
-d '{"username":"admin","password":"123456"}'
|
2026-03-12 19:49:48 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**预期响应:**
|
|
|
|
|
|
```json
|
|
|
|
|
|
{
|
|
|
|
|
|
"code": 200,
|
|
|
|
|
|
"message": "success",
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
"token": "eyJhbGc...",
|
|
|
|
|
|
"userId": 1,
|
|
|
|
|
|
"username": "admin",
|
|
|
|
|
|
"name": "平台管理员",
|
|
|
|
|
|
"role": "admin"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 4. 测试新 API 端点
|
|
|
|
|
|
|
|
|
|
|
|
使用返回的 token 测试受保护的接口:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
TOKEN="返回的token值"
|
|
|
|
|
|
|
|
|
|
|
|
# 查询主题列表
|
|
|
|
|
|
curl http://localhost:8080/api/v1/admin/themes \
|
|
|
|
|
|
-H "Authorization: Bearer $TOKEN"
|
|
|
|
|
|
|
|
|
|
|
|
# 查询课程套餐
|
|
|
|
|
|
curl http://localhost:8080/api/v1/admin/packages \
|
|
|
|
|
|
-H "Authorization: Bearer $TOKEN"
|
|
|
|
|
|
|
|
|
|
|
|
# 查询资源库
|
|
|
|
|
|
curl http://localhost:8080/api/v1/admin/resources/libraries \
|
|
|
|
|
|
-H "Authorization: Bearer $TOKEN"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 数据库配置
|
|
|
|
|
|
|
|
|
|
|
|
**数据库连接信息:**
|
|
|
|
|
|
```yaml
|
|
|
|
|
|
spring:
|
|
|
|
|
|
datasource:
|
|
|
|
|
|
url: jdbc:mysql://8.148.151.56:3306/reading_platform
|
|
|
|
|
|
username: root
|
|
|
|
|
|
password: reading_platform_pwd
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**已创建的数据表:**
|
|
|
|
|
|
- `t_admin_user` - 管理员用户
|
|
|
|
|
|
- `t_teacher` - 教师用户
|
|
|
|
|
|
- `t_parent` - 家长用户
|
|
|
|
|
|
- `t_student` - 学生
|
|
|
|
|
|
- `t_tenant` - 租户
|
|
|
|
|
|
- `course_package` - 课程套餐
|
|
|
|
|
|
- `course_package_course` - 套餐课程关联
|
|
|
|
|
|
- `tenant_package` - 租户套餐
|
|
|
|
|
|
- `course_lesson` - 课程环节
|
|
|
|
|
|
- `lesson_step` - 教学环节
|
|
|
|
|
|
- `lesson_step_resource` - 环节资源关联
|
|
|
|
|
|
- `theme` - 主题字典
|
|
|
|
|
|
- `t_resource_library` - 资源库
|
|
|
|
|
|
- `t_resource_item` - 资源项目
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## JWT 配置
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
|
jwt:
|
|
|
|
|
|
secret: readingPlatformJwtSecretKeyForTokenGeneration2024
|
|
|
|
|
|
expiration: 86400000 # 24小时(毫秒)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 已实现的 API 端点
|
|
|
|
|
|
|
|
|
|
|
|
### 认证接口
|
|
|
|
|
|
- `POST /api/auth/login` - 用户登录
|
|
|
|
|
|
- `GET /api/auth/me` - 获取当前用户信息
|
|
|
|
|
|
- `POST /api/auth/change-password` - 修改密码
|
|
|
|
|
|
|
|
|
|
|
|
### 超管端接口 (/api/v1/admin)
|
|
|
|
|
|
- **主题管理**: `/themes` - CRUD操作
|
|
|
|
|
|
- **课程套餐**: `/packages` - 创建、审核、发布、下线
|
|
|
|
|
|
- **课程环节**: `/courses/{courseId}/lessons` - 管理6种课程类型
|
|
|
|
|
|
- **资源库**: `/resources/libraries`, `/resources/items` - 资源库管理
|
|
|
|
|
|
- **文件上传**: `/files/upload` - 文件上传接口
|
|
|
|
|
|
|
|
|
|
|
|
### 学校端接口 (/api/v1/school)
|
|
|
|
|
|
- **套餐管理**: `/packages` - 查询、续费套餐
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 常见问题
|
|
|
|
|
|
|
|
|
|
|
|
### Q: 提示端口 8080 被占用
|
|
|
|
|
|
**A:** 查找并终止占用进程:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
lsof -ti :8080 | xargs kill -9
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Q: SDKMAN 命令找不到
|
|
|
|
|
|
**A:** 需要先加载 SDKMAN 环境:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
source "$HOME/.sdkman/bin/sdkman-init.sh"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Q: 编译失败
|
|
|
|
|
|
**A:** 清理并重新编译:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
mvn clean compile
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Q: 数据库连接失败
|
|
|
|
|
|
**A:** 检查网络连接和数据库服务状态
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 项目结构
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
reading-platform-java/
|
|
|
|
|
|
├── src/main/java/com/reading/platform/
|
|
|
|
|
|
│ ├── ReadingPlatformApplication.java # 启动类
|
|
|
|
|
|
│ ├── common/ # 公共组件
|
|
|
|
|
|
│ │ ├── annotation/ # 注解定义
|
|
|
|
|
|
│ │ ├── aspect/ # AOP切面
|
|
|
|
|
|
│ │ ├── config/ # 配置类
|
|
|
|
|
|
│ │ ├── enums/ # 枚举定义
|
|
|
|
|
|
│ │ ├── exception/ # 异常处理
|
|
|
|
|
|
│ │ ├── response/ # 响应封装
|
|
|
|
|
|
│ │ └── security/ # 安全模块
|
|
|
|
|
|
│ ├── controller/ # 控制器
|
|
|
|
|
|
│ │ ├── admin/ # 超管端
|
|
|
|
|
|
│ │ ├── school/ # 学校端
|
|
|
|
|
|
│ │ ├── teacher/ # 教师端
|
|
|
|
|
|
│ │ └── parent/ # 家长端
|
|
|
|
|
|
│ ├── dto/ # 数据传输对象
|
|
|
|
|
|
│ │ ├── request/ # 请求DTO
|
|
|
|
|
|
│ │ └── response/ # 响应DTO
|
|
|
|
|
|
│ ├── entity/ # 实体类
|
|
|
|
|
|
│ ├── mapper/ # MyBatis Mapper
|
|
|
|
|
|
│ ├── service/ # 业务逻辑
|
|
|
|
|
|
│ └── util/ # 工具类
|
|
|
|
|
|
├── src/main/resources/
|
|
|
|
|
|
│ ├── application.yml # 应用配置
|
|
|
|
|
|
│ └── db/migration/ # 数据库迁移脚本
|
|
|
|
|
|
└── pom.xml # Maven配置
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 技术栈
|
|
|
|
|
|
|
|
|
|
|
|
| 技术 | 版本 | 说明 |
|
|
|
|
|
|
|------|------|------|
|
|
|
|
|
|
| Java | 17.0.18 | Amazon Corretto |
|
|
|
|
|
|
| Spring Boot | 3.2.3 | 基础框架 |
|
|
|
|
|
|
| MyBatis-Plus | 3.5.5 | ORM框架 |
|
|
|
|
|
|
| MySQL Connector | 8.3.0 | 数据库驱动 |
|
|
|
|
|
|
| JWT | jjwt 0.12.5 | Token生成 |
|
|
|
|
|
|
| Knife4j | 4.4.0 | API文档 |
|
|
|
|
|
|
| Lombok | - | 代码简化 |
|
|
|
|
|
|
| Hutool | 5.8.26 | 工具库 |
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 开发模式提示
|
|
|
|
|
|
|
|
|
|
|
|
### 启用调试日志
|
|
|
|
|
|
在 `application.yml` 中设置:
|
|
|
|
|
|
```yaml
|
|
|
|
|
|
logging:
|
|
|
|
|
|
level:
|
|
|
|
|
|
com.reading.platform: debug
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 热重载(开发时)
|
|
|
|
|
|
使用 Spring Boot DevTools 可实现自动重载(需添加依赖)
|
|
|
|
|
|
|
|
|
|
|
|
### 测试账号
|
2026-03-14 16:50:54 +08:00
|
|
|
|
- **超管**: admin / 123456
|
2026-03-12 19:49:48 +08:00
|
|
|
|
- **学校**: school1 / 123456
|
|
|
|
|
|
- **教师**: teacher1 / 123456
|
|
|
|
|
|
- **家长**: parent1 / 123456
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
*最后更新: 2026-03-12 - Java后端环境配置完成*
|