Spring Boot+Vue3搭建CRUDDemo
一、项目选择与初始化一个典型的 CRUD Demo 项目是个人博客系统或仓库管理系统它们功能明确、技术栈成熟适合作为仓库初始内容。这里以Spring Boot Vue3 前后端分离博客系统为例进行说明 。1. 后端项目初始化 (Spring Boot)使用 Spring Initializr 快速生成项目骨架。# 使用 curl 命令生成项目 (示例) curl https://start.spring.io/starter.zip \ d typemaven-project \ -d languagejava \ d bootVersion3.2.5 \ d baseDirblog-backend \ d groupIdcom.example \ -d artifactIdblog \ -d nameblog \ d descriptionSpring Boot Blog Backend \ -d packageNamecom.example.blog \ -d packagingjar \ d javaVersion17 \ d dependenciesweb,data-jpa,mysql,validation,security \ o blog-backend.zip解压后得到标准的 Maven 项目结构 。2. 前端项目初始化 (Vue3)使用 Vite 快速创建 Vue3 项目。# 使用 npm 创建项目 npm create vuelatest blog-frontend # 根据提示选择配置例如加入 Router, Pinia 等 cd blog-frontend npm install npm run dev二、核心 CRUD 功能实现以文章管理为例1. 后端实体与 Repository (Spring Data JPA)// src/main/java/com/example/blog/entity/Article.java package com.example.blog.entity; import jakarta.persistence.*; import lombok.Data; import java.time.LocalDateTime; Entity Data Table(name articles) public class Article { Id GeneratedValue(strategy GenerationType.IDENTITY) private Long id; private String title; Lob private String content; private String author; private LocalDateTime createTime; private LocalDateTime updateTime; }// src/main/java/com/example/blog/repository/ArticleRepository.java package com.example.blog.repository; import com.example.blog.entity.Article; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; Repository public interface ArticleRepository extends JpaRepositoryArticle, Long { }2. 后端 Service 与 Controller (RESTful API)// src/main/java/com/example/blog/service/ArticleService.java package com.example.blog.service; import com.example.blog.entity.Article; import com.example.blog.repository.ArticleRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; Service public class ArticleService { Autowired private ArticleRepository articleRepository; public ListArticle findAll() { return articleRepository.findAll(); } public OptionalArticle findById(Long id) { return articleRepository.findById(id); } public Article save(Article article) { if (article.getId() null) { article.setCreateTime(LocalDateTime.now()); } article.setUpdateTime(LocalDateTime.now()); return articleRepository.save(article); } public void deleteById(Long id) { articleRepository.deleteById(id); } }// src/main/java/com/example/blog/controller/ArticleController.java package com.example.blog.controller; import com.example.blog.entity.Article; import com.example.blog.service.ArticleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Optional; RestController RequestMapping(/api/articles) public class ArticleController { Autowired private ArticleService articleService; GetMapping public ResponseEntityListArticle getAllArticles() { return ResponseEntity.ok(articleService.findAll()); } GetMapping(/{id}) public ResponseEntityArticle getArticleById(PathVariable Long id) { OptionalArticle article articleService.findById(id); return article.map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } PostMapping public ResponseEntityArticle createArticle(RequestBody Article article) { return ResponseEntity.ok(articleService.save(article)); } PutMapping(/{id}) public ResponseEntityArticle updateArticle(PathVariable Long id, RequestBody Article article) { if (!articleService.findById(id).isPresent()) { return ResponseEntity.notFound().build(); } article.setId(id); return ResponseEntity.ok(articleService.save(article)); } DeleteMapping(/{id}) public ResponseEntityVoid deleteArticle(PathVariable Long id) { if (!articleService.findById(id).isPresent()) { return ResponseEntity.notFound().build(); } articleService.deleteById(id); return ResponseEntity.noContent().build(); } }3. 前端页面与 API 调用 (Vue3 Composition API Axios)!-- src/views/ArticleList.vue -- template div h1文章列表/h1 button clickshowCreateForm新建文章/button ul li v-forarticle in articles :keyarticle.id {{ article.title }} - {{ article.author }} button clickeditArticle(article)编辑/button button clickdeleteArticle(article.id)删除/button /li /ul !-- 创建/编辑表单 -- div v-ifshowForm h2{{ formTitle }}/h2 form submit.preventsubmitForm input v-modelcurrentArticle.title placeholder标题 required / textarea v-modelcurrentArticle.content placeholder内容 required/textarea input v-modelcurrentArticle.author placeholder作者 required / button typesubmit提交/button button typebutton clickcancelForm取消/button /form /div /div /template script setup import { ref, onMounted } from vue import axios from axios const API_BASE http://localhost:8080/api/articles const articles ref([]) const showForm ref(false) const formTitle ref() const currentArticle ref({ id: null, title: , content: , author: }) // 获取文章列表 const fetchArticles async () { try { const response await axios.get(API_BASE) articles.value response.data } catch (error) { console.error(获取文章失败:, error) } } // 创建文章 const createArticle async (article) { await axios.post(API_BASE, article) fetchArticles() } // 更新文章 const updateArticle async (id, article) { await axios.put(${API_BASE}/${id}, article) fetchArticles() } // 删除文章 const deleteArticle async (id) { if (confirm(确定删除吗)) { await axios.delete(${API_BASE}/${id}) fetchArticles() } } // 表单操作 const showCreateForm () { currentArticle.value { id: null, title: , content: , author: } formTitle.value 创建文章 showForm.value true } const editArticle (article) { currentArticle.value { ...article } formTitle.value 编辑文章 showForm.value true } const submitForm () { if (currentArticle.value.id) { updateArticle(currentArticle.value.id, currentArticle.value) } else { createArticle(currentArticle.value) } cancelForm() } const cancelForm () { showForm.value false } onMounted(() { fetchArticles() }) /script三、数据库配置与连接1. 后端application.properties配置# src/main/resources/application.properties spring.application.nameblog-backend server.port8080 # 数据库配置 (MySQL示例) spring.datasource.urljdbc:mysql://localhost:3306/blog_db?useSSLfalseserverTimezoneUTCcharacterEncodingutf8 spring.datasource.usernameroot spring.datasource.passwordyourpassword spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver # JPA 配置 spring.jpa.hibernate.ddl-autoupdate spring.jpa.show-sqltrue spring.jpa.properties.hibernate.dialectorg.hibernate.dialect.MySQL8Dialect spring.jpa.properties.hibernate.format_sqltrue2. 初始化 SQL 脚本 (可选)-- 创建数据库CREATE DATABASE IF NOT EXISTS blog_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE blog_db; -- 创建文章表 (JPA的ddl-autoupdate通常会自动生成) CREATE TABLE IF NOT EXISTS articles ( id BIGINT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(255) NOT NULL, content TEXT, author VARCHAR(100), create_time DATETIME, update_time DATETIME );四、项目结构与关键文件一个完整的 CRUD Demo 仓库应包含以下核心结构blog-demo/ ├── blog-backend/ # Spring Boot 后端 │ ├── src/ │ │ ├── main/ │ │ │ ├── java/com/example/blog/ │ │ │ │ ├── entity/ # 实体类 (如 Article.java) │ │ │ │ ├── repository/ # 数据访问层 (如 ArticleRepository.java) │ │ │ │ ├── service/ # 业务逻辑层 (如 ArticleService.java) │ │ │ │ ├── controller/ #控制层 (如 ArticleController.java) │ │ │ │ └── BlogApplication.java # 主启动类 │ │ │ └── resources/ │ │ │ ├── application.properties # 配置文件 │ │ │ └── static/ # 静态资源 │ │ └── test/ # 单元测试 │ └── pom.xml # Maven 依赖管理 │ ├── blog-frontend/ # Vue3 前端 │ ├── src/ │ │ ├── views/ # 页面组件 (如 ArticleList.vue) │ │ ├── router/ # 路由配置 │ │ ├── stores/ # 状态管理 (如 Pinia) │ │ ├── api/ # API 请求封装 (如 axios 实例) │ │ └── main.js # 应用入口 │ ├── public/ │ ├── index.html │ ├── package.json │ └── vite.config.js │ ├── database/ # 数据库脚本 │ └── init.sql │ ├── README.md # 项目说明文档└── .gitignore # Git 忽略文件配置五、快速启动与验证1. 后端启动cd blog-backend ./mvnw spring-boot:run # 或使用 Maven mvn spring-boot:run访问http://localhost:8080/api/articles测试 API 。2. 前端启动cd blog-frontend npm install npm run dev访问http://localhost:5173操作前端界面。3.接口测试 (使用 curl)# 创建文章 curl -X POST http://localhost:8080/api/articles \ H Content-Type: application/json \ -d {title:第一篇博客,content:Hello World!,author:张三} # 查询文章列表 curl http://localhost:8080/api/articles # 更新文章 (假设id为1) curl -X PUT http://localhost:8080/api/articles/1 \ H Content-Type: application/json \ -d {title:更新后的标题,content:更新内容,author:李四} # 删除文章 (假设id为1) curl -X DELETE http://localhost:8080/api/articles/1六、仓库准备与提交1. 本地 Git 初始化# 在项目根目录 (blog-demo) 执行 git init git add . git commit -m Initial commit: Spring Boot Vue3 CRUD Blog Demo2. 推送到远程仓库 (以 GitHub 为例)# 在 GitHub 上创建新仓库例如名为 springboot-vue3-blog-demo git remote add origin https://github.com/your-username/springboot-vue3-blog-demo.git git branch -M main git push -u origin main3.README.md核心内容示例# Spring Boot Vue3 博客系统 CRUD Demo 一个完整的前后端分离博客系统示例涵盖文章的增加、删除、修改、查询功能。 ## 技术栈 **后端**: Spring Boot 3, Spring Data JPA, MySQL, RESTful API - **前端**: Vue3, Composition API, Axios, Vite - **数据库**: MySQL 8.0 ## 快速开始 1. 克隆项目: git clone https://github.com/your-username/springboot-vue3-blog-demo.git 2. 导入数据库: 执行 database/init.sql 3. 启动后端: cd blog-backend mvn spring-boot:run 4. 启动前端: cd blog-frontend npm install npm run dev 5. 访问前端: http://localhost:5173 ##核心功能 文章列表展示 新建/编辑/删除文章 基于 RESTful API 的前后端通信 ## 接口文档 GET /api/articles获取所有文章 - POST /api/articles - 创建新文章 PUT /api/articles/{id}更新文章 DELETE /api/articles/{id}删除文章通过以上步骤你将拥有一个结构清晰、功能完整、可直接运行和展示的 CRUD Demo 项目仓库完全符合 GitHub/Gitee 的托管要求 。参考来源SpringBoot仓库管理系统实战从架构设计到代码实现深度解析半小时搭建SpringBootVue3博客系统全栈开发实战指南计算机毕业设计实战Java/Python/PHP/Node.js构建个人记账系统一小时搭建Spring BootVue3博客系统从环境配置到部署上线基于SpringBoot的校园二手交易平台从零搭建与毕设实战指南

相关新闻

Python爬虫实战:淘宝商品数据抓取与反爬策略

Python爬虫实战:淘宝商品数据抓取与反爬策略

1. 爬虫技术入门与实战案例解析 最近在技术社区看到不少关于爬虫的讨论,从微信公众号数据抓取到电商平台商品信息采集,爬虫技术似乎成了数据获取的标配工具。作为一个长期和数据打交道的开发者,我完整经历过从爬虫小白到能处理各种反爬机制的…

2026/9/29 6:22:44 阅读更多 →
Origin2021安装全攻略:从环境配置到错误排查的完整解决方案

Origin2021安装全攻略:从环境配置到错误排查的完整解决方案

1. 项目概述:当Origin2021安装成为一场“技术排雷”如果你正在为Origin2021的安装而头疼,相信我,你绝对不是一个人。作为一款在科研绘图和数据分析领域拥有庞大用户基础的软件,OriginLab系列以其强大的功能著称,但其安…

2026/10/14 19:14:59 阅读更多 →
483. Java 反射 - 调用构造器

483. Java 反射 - 调用构造器

文章目录483. Java 反射 - 调用构造器1. 定位构造器 (Locating Constructors)2. 示例:获取 String 类的构造器输出结果(JDK 23 中部分示例):3. 获取特定构造器4. 调用构造器创建实例5. 总结483. Java 反射 - 调用构造器 在反射中…

2026/10/14 4:15:37 阅读更多 →

最新新闻

乐企增值税抵扣勾选V3.010实战:从发票池到申报表的全链路对接指南

乐企增值税抵扣勾选V3.010实战:从发票池到申报表的全链路对接指南

简介:乐企增值税抵扣勾选能力说明文档V3.010面向企业财税人员、发票管理岗及对接乐企开放平台的开发与测试人员,围绕增值税抵扣勾选这一税务合规关键环节,系统梳理接口调用与业务场景处理逻辑。资源包内含1个docx文档,大小约10.67…

2026/10/14 19:14:23 阅读更多 →
你的论文在AI检测面前“裸奔”了多久?——云智变AI降重降AIGC功能一次说透|云智变AI官网www.yunzhibian.cn 微信公众号搜一搜云智变ai学术

你的论文在AI检测面前“裸奔”了多久?——云智变AI降重降AIGC功能一次说透|云智变AI官网www.yunzhibian.cn 微信公众号搜一搜云智变ai学术

你有没有经历过这种荒诞感:论文明明是自己一个字一个字敲出来的,查重率只有8%,提交系统后却收到一条通知——“AIGC疑似率67%,请整改后重新送审。” 这不是段子。2026年,知网、维普、万方三大平台全部上线了AIGC检测模…

2026/10/14 19:14:23 阅读更多 →
宏翔上位机定制开发助力工厂数据化升级实战

宏翔上位机定制开发助力工厂数据化升级实战

在不少传统制造车间里,设备轰鸣作响,但数据却像被锁在了一个个独立的黑盒子里。注塑机、冲压机、装配线各自为政,操作员每天要往返于不同的控制台记录参数,质检员对着纸质报表核对批次,管理层想要看实时的产能状况&…

2026/10/14 19:14:23 阅读更多 →
光学工程师笔试高频考点精解:图解法、入瞳渐晕与系统建模

光学工程师笔试高频考点精解:图解法、入瞳渐晕与系统建模

简介:本资源是面向光学工程领域求职者与在校学生的专业笔试备考资料,聚焦光学系统设计、成像分析与工程计算三大核心能力训练。内容涵盖图解法求像(含基点定位与成像方向判断)、光学基础填空(照明/转像系统、近视镜焦距…

2026/10/14 19:14:23 阅读更多 →
FastAdmin列表操作按钮开发指南:渲染原理与实战避坑

FastAdmin列表操作按钮开发指南:渲染原理与实战避坑

给FastAdmin列表加个操作按钮,听起来是个再基础不过的需求,真做起来却经常让人抓狂:代码写完不到十分钟,按钮却怎么都不显示;权限开了半天,别人还是看不到;好不容易出来了,点击又没反…

2026/10/14 19:14:23 阅读更多 →
CPR 1.3.0 C++ HTTP库构建与链接避坑指南

CPR 1.3.0 C++ HTTP库构建与链接避坑指南

简介:本资源为C开发者快速集成HTTP客户端功能提供的预编译cpr库(1.3.0版本),面向使用Visual Studio 2015进行Windows平台C开发的中初级工程师及学习者,有效规避源码编译依赖复杂、环境配置繁琐等常见痛点。压缩包共27个…

2026/10/14 19:13:23 阅读更多 →

日新闻

AnyPS5通用适配层设计:兼容性与性能的工程取舍

AnyPS5通用适配层设计:兼容性与性能的工程取舍

1. 从"AnyPS5"这个名字说起:它到底想解决什么问题第一次看到"AnyPS5"这个标题,我脑子里冒出来的第一个念头是:这大概率是一个围绕"跨平台运行"或者"通用适配"做文章的项目。名字里的"Any"…

2026/10/14 0:00:41 阅读更多 →
Flutter跨平台开发实战:二手交易应用与HarmonyOS适配

Flutter跨平台开发实战:二手交易应用与HarmonyOS适配

1. 项目概述:Flutter跨平台二手交易应用开发作为一名长期从事移动应用开发的工程师,我最近完成了一个基于Flutter框架的二手物品交易平台项目。这个项目最吸引我的地方在于它完美结合了Flutter的跨平台优势与HarmonyOS的生态特性,实现了"…

2026/10/14 0:00:41 阅读更多 →
DFS算法解决飞机降落调度问题实战

DFS算法解决飞机降落调度问题实战

1. 项目背景与核心思路飞机降落问题是一个经典的调度优化场景,也是算法竞赛和面试中的高频题目。这个题目要求我们合理安排多架飞机的降落顺序和时间,确保所有飞机都能安全着陆而不发生冲突。在实际航空管制中,这类问题直接关系到飞行安全和机…

2026/10/14 0:00:41 阅读更多 →

周新闻

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

简介:基于 ARIMA、LSTM、Transformer 等模型的流感时间序列预测 Python 源码,面向计算机相关专业课程设计与期末大作业学生,以及项目实战学习者。内容覆盖预处理、平稳性检验、定阶、残差分析、多模型对比预测的完整时序建模流程,…

2026/10/14 3:30:28 阅读更多 →
影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别 做影刀RPA自动化,十个新手有八个栽在"往输入框里填东西"这件事上:要么填不进去,要么填了一半,要么直接把原来内容追加在后面。这背后的根因&…

2026/10/14 16:30:29 阅读更多 →
影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容 1. 认识影刀:什么场景该用RPA采小说数据 起点中文网的页面结构相对稳定——分类榜单、书籍详情、章节内容三块独立页面,跳转链路清晰。这种场景非常适合影刀自动化&#x…

2026/10/14 3:29:58 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/13 22:01:27 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/13 14:57:39 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/14 7:53:34 阅读更多 →