refactor: 全站改用数据库动态驱动,支持分类与统计动态查询,并全面将作者及博主标识由'旺总'切换为'小东'
Build and Deploy Blog / deploy (push) Successful in 40s

This commit is contained in:
2026-10-22 16:59:00 +08:00
parent ae840a47a9
commit 9ad9923d61
4 changed files with 65 additions and 29 deletions
@@ -49,7 +49,7 @@ public class DataInitializer implements CommandLineRunner {
"相比传统臃肿的面料,1Panel 深度拥抱 **Docker 容器化**,所有应用(MySQL、OpenResty、Gitea)完全容器隔离,真正做到“环境随用随建,数据挂载持久化”。\n\n" +
"```bash\n# 快速检查 Docker 运行状态\ndocker ps --format \"table {{.Names}}\\t{{.Status}}\\t{{.Ports}}\"\n```\n\n" +
"> 💡 **运维心得**:永远在云平台控制台统一放行防火墙端口,切勿盲目在系统内部启用 UFW,避免失联风险。");
p1.setAuthor("旺总");
p1.setAuthor("小东");
p1.setCategoryName("云原生 & Linux");
p1.setTags("GCP,Ubuntu,1Panel,Linux");
p1.setReadTime("4 min");
@@ -72,7 +72,7 @@ public class DataInitializer implements CommandLineRunner {
"3. **清空全局默认 Prompt**:消除了默认附带的 2050 历史 Token,读题耗时从 60s 骤降至 0.2s!\n\n" +
"```bash\n# 测试模型运行性能\ndocker exec -it 1Panel-ollama-nzre ollama run qwen2.5:1.5b --verbose\n```\n\n" +
"> 纯 CPU 跑 7B 参数是物理带宽瓶颈,日常开发推荐搭配 1.5B~3B 模型,速度与逻辑达到最佳平衡!");
p2.setAuthor("旺总");
p2.setAuthor("小东");
p2.setCategoryName("AI & 本地模型");
p2.setTags("DeepSeek,Ollama,OpenWebUI,性能调优");
p2.setReadTime("6 min");
@@ -90,7 +90,7 @@ public class DataInitializer implements CommandLineRunner {
"- 数据文件挂载至命名卷 `mysql_data`,容器重启或重建数据零丢失;\n" +
"- Spring Data JPA 实现对象关系映射,自动完成数据库结构维护;\n" +
"- 统一 RESTful API 与响应封装,全栈开发得心应手!");
p3.setAuthor("旺总");
p3.setAuthor("小东");
p3.setCategoryName("全栈开发 & CI/CD");
p3.setTags("Spring Boot,MySQL,JPA,CI/CD");
p3.setReadTime("5 min");
@@ -99,5 +99,18 @@ public class DataInitializer implements CommandLineRunner {
postRepository.saveAll(Arrays.asList(p1, p2, p3));
}
// 3. 自动迁移平滑更新:如果数据库中存留历史旧作者"旺总",自动同步更新为"小东"
List<Post> existingPosts = postRepository.findAll();
boolean hasMigration = false;
for (Post p : existingPosts) {
if ("旺总".equals(p.getAuthor())) {
p.setAuthor("小东");
hasMigration = true;
}
}
if (hasMigration) {
postRepository.saveAll(existingPosts);
}
}
}
@@ -21,7 +21,7 @@ public class Post {
private String content;
@Column(length = 50)
private String author = "旺总";
private String author = "小东";
@Column(name = "category_name", length = 50)
private String categoryName = "技术杂谈";
@@ -51,7 +51,7 @@ public class Post {
if (updatedAt == null) updatedAt = LocalDateTime.now();
if (views == null) views = 0;
if (likes == null) likes = 0;
if (author == null) author = "旺总";
if (author == null) author = "小东";
if (categoryName == null) categoryName = "技术杂谈";
if (readTime == null) readTime = "3 min";
if (status == null) status = "PUBLISHED";