去年帮学弟调试毕业设计时,我完整走通了SpringBoot+Vue的全栈博客开发流程。这个技术组合既能满足高校对Java技术栈的考核要求,又符合当前企业级开发的主流趋势。系统采用经典的前后端分离架构,前端用Vue3+Element Plus实现响应式界面,后端基于SpringBoot 2.7提供RESTful API,数据库选用MySQL 8.0,配合Redis缓存提升性能。
提示:建议开发环境统一使用JDK17+Node16+IDEA2022组合,避免版本兼容性问题
SpringBoot作为基础框架,主要依赖包括:
数据库设计遵循三范式原则,核心表包括:
sql复制CREATE TABLE `article` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`content` longtext,
`user_id` int DEFAULT NULL,
`view_count` int DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Vue3组合式API开发,主要技术点:
典型组件结构:
code复制src/
├── api/ # 接口定义
├── assets/ # 静态资源
├── components/ # 公共组件
│ ├── Editor.vue # 富文本编辑器
│ └── Header.vue # 导航栏
├── router/ # 路由配置
├── stores/ # 状态管理
└── views/ # 页面组件
/api/article接口提交JSON数据:json复制{
"title": "SpringBoot实战",
"content": "## 1. 项目创建...",
"tags": ["Java", "后端"]
}
@TableField处理HTML转义:java复制@TableField(typeHandler = HtmlEscapeTypeHandler.class)
private String content;
采用JWT+Spring Security的认证流程:
java复制String token = Jwts.builder()
.setSubject(username)
.setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000))
.signWith(SignatureAlgorithm.HS512, "yourSecretKey")
.compact();
javascript复制service.interceptors.request.use(config => {
config.headers['Authorization'] = 'Bearer ' + getToken()
return config
})
后端配置类需添加:
java复制@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
java复制Page<Article> page = new Page<>(current, size);
articleMapper.selectPage(page, Wrappers.<Article>lambdaQuery()
.orderByDesc(Article::getCreateTime));
java复制@Cacheable(value = "hotArticles", key = "#root.methodName")
public List<Article> getHotArticles() {
return articleMapper.selectList(...);
}
pom.xml需添加:
xml复制<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
javascript复制module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/blog/'
: '/',
outputDir: 'dist',
assetsDir: 'static'
}
nginx复制location / {
root /usr/share/nginx/html/blog;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:8080;
}
我在实际开发中发现,使用Docker Compose统一管理服务能显著降低部署复杂度。建议在docker-compose.yml中定义MySQL、Redis等服务,配合GitHub Actions实现CI/CD自动化部署。