commit cb08080ca723b9d286bad2eb661949155ef5d262 Author: admin Date: Thu Oct 22 06:29:05 2026 +0000 feat: 初始化 SpringBoot + 前端全栈博客项目 diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..07570b3 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.9-eclipse-temurin-17 AS builder +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +FROM eclipse-temurin:17-jre +WORKDIR /app +COPY --from=builder /app/target/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/backend/pom.xml b/backend/pom.xml new file mode 100644 index 0000000..63fd831 --- /dev/null +++ b/backend/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.3 + + + com.example + my-blog-backend + 1.0.0 + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/backend/src/main/java/com/example/blog/BlogApplication.java b/backend/src/main/java/com/example/blog/BlogApplication.java new file mode 100644 index 0000000..fb5da18 --- /dev/null +++ b/backend/src/main/java/com/example/blog/BlogApplication.java @@ -0,0 +1,41 @@ +package com.example.blog; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.*; +import java.util.*; + +@SpringBootApplication +@RestController +@CrossOrigin(origins = "*") +@RequestMapping("/api/posts") +public class BlogApplication { + + private static final List> posts = new ArrayList<>(); + + static { + Map p1 = new HashMap<>(); + p1.put("id", "1"); + p1.put("title", "Hello World! 我的第一篇云端博客"); + p1.put("content", "这是运行在 Google Cloud 台湾节点上的 Spring Boot 3.x 容器!"); + p1.put("author", "旺总"); + p1.put("date", "2026-10-22"); + posts.add(p1); + } + + @GetMapping + public List> getPosts() { + return posts; + } + + @PostMapping + public Map addPost(@RequestBody Map post) { + post.put("id", String.valueOf(posts.size() + 1)); + posts.add(0, post); + return post; + } + + public static void main(String[] args) { + SpringApplication.run(BlogApplication.class, args); + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d40e026 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.8' +services: + backend: + build: ./backend + container_name: blog-backend + restart: always + ports: + - "8089:8080" + + frontend: + image: nginx:alpine + container_name: blog-frontend + restart: always + ports: + - "8088:80" + volumes: + - ./frontend:/usr/share/nginx/html diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..868ed42 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,80 @@ + + + + + 我的个人技术博客 + + + +
+
+

⚡ 旺总的技术全栈博客

+

基于 Spring Boot 3 + Vue 架构 · Docker 容器驱动 · CI/CD 自动部署

+
+ +
+ + + + +
+ +
加载中...
+
+ + + +