🤖 Assistant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 📚 SpringBoot + Vue 项目知识点总结  

## 🚀 学习路径
1. **前置知识**
- ✅ Java 基础 + Spring 框架
- ✅ Vue.js 基础(组件、路由、状态管理)
- ✅ RESTful API 概念
- ✅ MySQL / PostgreSQL 数据库基础

2. **学习顺序**
- **后端(SpringBoot)→ 前端(Vue)→ 整合(前后端分离开发)**

---

## 📌 核心知识点

### 🛠 **后端(SpringBoot)**
1. **基础框架**
- `@SpringBootApplication` 启动类
- `Spring MVC` 架构(Controller-Service-Repository)
- `Spring Data JPA` / `MyBatis` 数据库操作

2. **核心注解**
- `@RestController` (返回 JSON)
- `@RequestMapping` / `@GetMapping` / `@PostMapping`
- `@Autowired` 依赖注入

3. **数据库 & ORM**
- JPA 方法命名查询 / `@Query`
- `@Entity` 实体类映射
- 分页(`Pageable`

4. **安全 & 认证**
- `Spring Security` / `JWT` 鉴权

5. **API 规范**
- RESTful 接口设计
- Swagger / OpenAPI 文档

---

### 🎨 **前端(Vue)**
1. **核心概念**
- Vue 组件化开发
- 数据绑定(`v-model`
- 生命周期钩子(`created`, `mounted`

2. **状态管理**
- `Vuex`(集中式状态)
- `Pinia`(推荐新项目使用)

3. **路由**
- `vue-router`(动态路由、嵌套路由)

4. **HTTP 请求**
- `axios` 调用后端 REST API

5. **UI 框架(可选)**
- Element Plus / Ant Design Vue

---

## 🔥 快速搭建 SpringBoot + Vue 项目

### 步骤 1: 初始化后端(SpringBoot)
1. 使用 [Spring Initializr](https://start.spring.io/) 生成项目:
- 勾选 `Spring Web`, `Lombok`, `Spring Data JPA`, `MySQL Driver`

2. 编写 `UserController`:
```java
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService userService;

@GetMapping
public List<User> getAllUsers() {
return userService.findAll();
}
}
  1. 配置 application.properties:
    1
    2
    3
    spring.datasource.url=jdbc:mysql://localhost:3306/your_db
    spring.datasource.username=root
    spring.datasource.password=123456

步骤 2: 初始化前端(Vue)

  1. 用 Vite 创建 Vue 项目:

    1
    2
    npm init vite@latest frontend --template vue
    cd frontend && npm install axios vue-router pinia
  2. 调用后端 API(src/api/user.js):

    1
    2
    3
    4
    5
    import axios from 'axios';

    export const getUsers = () => {
    return axios.get('http://localhost:8080/api/users');
    };
  3. 跨域配置(vite.config.js):

    1
    2
    3
    4
    5
    6
    7
    export default defineConfig({
    server: {
    proxy: {
    '/api': 'http://localhost:8080'
    }
    }
    });

📝 学习资源推荐

  • SpringBoot: Baeldung / 官方文档
  • Vue: 官方文档 + Vue Mastery 教程
  • 实战: GitHub 开源项目(如 eladmin-web + eladmin

🌟 学习建议

  • 先单独调试后端(Postman 测试 API)
  • 再调试前端(Chrome DevTools 看请求)
  • 最后联调(解决跨域、数据格式问题)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

### 🎯 效果说明
- 使用了 Emoji 图标增强可读性
- 分模块拆解知识点
- 提供可操作的代码片段
- 强调前后端分离的核心逻辑

### 🤖 Assistant

```markdown
# 🌱 SpringBoot + Vue 全栈开发指南

## 🏗️ 一、技术架构概览
### 后端技术栈 (SpringBoot)
```mermaid
graph TD
A[SpringBoot] --> B[Spring MVC]
A --> C[Spring Security]
A --> D[MyBatis/MyBatis-Plus]
A --> E[Spring Data JPA]
F[MySQL/PostgreSQL] --> D
G[Redis] --> C

前端技术栈 (Vue)

1
2
3
4
5
6
graph TD
A[Vue3] --> B[Vue Router]
A --> C[Pinia/Vuex]
A --> D[Axios]
A --> E[Element Plus/Ant Design Vue]
A --> F[Vite]

📚 二、完整学习路径

1. 基础阶段(2-4周)

后端基础

  • ✅ SpringBoot核心特性
    • 自动配置原理
    • Starter机制
    • Actuator监控
  • ✅ RESTful API设计
    • 常用注解:@RestController, @RequestMapping
    • 统一响应封装
    • 全局异常处理

前端基础

  • 🖥️ Vue3核心语法
    • Composition API
    • 响应式原理(ref/reactive)
    • 组件通信
  • 🌐 Vue Router 4.x
    • 动态路由
    • 导航守卫
    • 路由懒加载

2. 进阶阶段(3-5周)

后端进阶

  • 🛡️ 安全控制
    • JWT实现
    • Spring Security配置
    • 权限注解(@PreAuthorize)
  • 🔄 数据持久化
    • MyBatis动态SQL
    • 多数据源配置
    • 事务管理

前端进阶

  • 🏪 状态管理
    • Pinia基础
    • 模块化设计
    • 持久化存储
  • 📡 网络请求
    • Axios封装
    • 请求拦截器
    • 错误统一处理

🚀 三、项目快速搭建指南

1. 环境准备

1
2
3
4
5
6
7
8
# 后端环境
JDK 17+
Maven 3.8+
MySQL 8.0

# 前端环境
Node.js 16+
npm/yarn/pnpm

2. 项目初始化

后端创建

1
2
3
4
5
6
7
8
# 使用Spring Initializr
https://start.spring.io/

选择依赖:
- Spring Web
- Lombok
- MyBatis Framework
- MySQL Driver

前端创建

1
2
3
npm create vite@latest frontend --template vue
cd frontend
npm install vue-router pinia axios element-plus

3. 关键配置示例

后端配置

1
2
3
4
5
6
7
8
9
10
// application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/demo
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:
mapper-locations: classpath:mapper/*.xml

前端配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath } from 'url'

export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true
}
}
}
})

🔧 四、开发实用技巧

跨域解决方案

1
2
3
4
5
6
7
8
9
10
11
// 后端配置CORS
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.maxAge(3600);
}
}

全局异常处理

1
2
3
4
5
6
7
8
9
@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(Exception.class)
@ResponseBody
public Result<String> handleException(Exception e) {
return Result.error(e.getMessage());
}
}

前端API封装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// src/api/index.js
import axios from 'axios'

const service = axios.create({
baseURL: '/api',
timeout: 10000
})

// 请求拦截器
service.interceptors.request.use(config => {
const token = localStorage.getItem('token')
if (token) {
config.headers['Authorization'] = `Bearer ${token}`
}
return config
})

// 响应拦截器
service.interceptors.response.use(
response => {
return response.data
},
error => {
return Promise.reject(error)
}
)

export default service

📦 五、部署方案

1. 后端打包

1
2
mvn clean package -DskipTests
java -jar target/demo-0.0.1-SNAPSHOT.jar

2. 前端打包

1
npm run build

3. 部署架构选择

1
2
3
4
5
6
7
8
9
10
11
1. 传统部署
- Nginx反向代理
- 静态资源部署

2. Docker化部署
- Docker Compose编排
- Nginx容器配置

3. CI/CD方案
- Jenkins Pipeline
- GitHub Actions

📝 六、学习资源推荐

  • 书籍:
    • 《Spring Boot实战》
    • 《Vue.js设计与实现》
  • 视频:
    • B站尚硅谷SpringBoot+Vue全栈课程
  • 文档:
  • 社区:
    • StackOverflow
    • GitHub热门开源项目

🚨 常见问题排查

  1. 端口冲突:检查8080/3000端口占用
  2. 数据库连接失败:检查MySQL服务状态和账号权限
  3. 跨域问题:确保前后端CORS配置正确
  4. 前端路由404:配置Nginx重定向规则

    1