feat: 初始化 SpringBoot + 前端全栈博客项目

This commit is contained in:
admin
2026-10-22 06:29:05 +00:00
commit cb08080ca7
5 changed files with 180 additions and 0 deletions
+11
View File
@@ -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"]
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>my-blog-backend</artifactId>
<version>1.0.0</version>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -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<Map<String, String>> posts = new ArrayList<>();
static {
Map<String, String> 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<Map<String, String>> getPosts() {
return posts;
}
@PostMapping
public Map<String, String> addPost(@RequestBody Map<String, String> 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);
}
}