feat: 初始化 SpringBoot + 前端全栈博客项目
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user