Element UI+Spring Boot进行CRUD的实例

ElementUI安装与使用指南

前端代码:点击查看learnelementuispringboot项目源码

后端代码:点击查看 LearnElementUiAndSpringBoot

一、前端配置

安装axios

  • axios官网
  • axios中文文档
  • 安装指令:npm install axios

在这里插入图片描述

二、后端配置

  • springboot3
  • mybatis-plus 官网安装教程
  • MySQL数据库
    数据库book表的结构如下图

在这里插入图片描述

效果图

在这里插入图片描述

crud-query-delete.vue(CRUD实例)页面效果图
在这里插入图片描述

在这里插入图片描述

crud-update.vue(编辑)页面效果图
在这里插入图片描述
在这里插入图片描述

crud-insert.vue(添加)页面效果图
在这里插入图片描述

项目结构

一、后端
在这里插入图片描述
二、前端
在这里插入图片描述

三、前端代码

1、crud-query-delete.vue代码

import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ElementUI from "@/views/ElementUI.vue";
import PagePath from "@/components/PagePath.vue";
import ElButton from "@/views/el-button.vue";
import ElLink from "@/views/el-link.vue";
import ElRadio from "@/views/el-radio.vue";
import ElRow_elCol from "@/views/el-row_el-col.vue";
import ElContainer from "@/views/el-container.vue";
import ElContainerExample from "@/views/el-container-example.vue";
import ElCheckbox from "@/views/el-checkbox.vue";
import ElInput from "@/views/el-input.vue";
import ElInputNumber from "@/views/el-input-number.vue";
import ElSwitch from "@/views/el-switch.vue";
import ElUpload from "@/views/el-upload.vue";
import ElForm from "@/views/el-form.vue";
import ElSelect from "@/views/el-select.vue";
import ElTable from "@/views/el-table.vue";
import CrudQueryDelete from "@/views/crud-query-delete.vue";
import CrudUpdate from "@/views/crud-update.vue";
import CrudInsert from "@/views/crud-insert.vue";Vue.use(VueRouter)const routes = [{path: PagePath.crud_insert,name: 'crud-insert',component: CrudInsert},{path: PagePath.crud_update,name: 'crud-update',component: CrudUpdate},{path: PagePath.crud_query_delete,name: 'crud-query-delete',component: CrudQueryDelete},{path: PagePath.el_table,name: 'el-table',component: ElTable},{path: PagePath.el_select,name: 'el-select',component: ElSelect},{path: PagePath.el_form,name: 'el-form',component: ElForm},{path: PagePath.el_upload,name: 'el-upload',component: ElUpload},{path: PagePath.el_switch,name: 'el-switch',component: ElSwitch},{path: PagePath.el_input_number,name: 'el-input-number',component: ElInputNumber},{path: PagePath.el_input,name: 'el-input',component: ElInput},{path: PagePath.el_checkbox,name: 'el-checkbox',component: ElCheckbox},{path: PagePath.el_container_example,name: 'el-container-example',component: ElContainerExample},{path: PagePath.el_container,name: 'el-container',component: ElContainer},{path: PagePath.el_row_el_col,name: 'el-row_el-col',component: ElRow_elCol},{path: PagePath.el_radio,name: 'el-link',component: ElRadio},{path: PagePath.el_link,name: 'el-link',component: ElLink},{// path: '/el_button',// path: PagePath.data().el_button,path: PagePath.el_button,name: 'el-button',component: ElButton},{path: '/element_ui',name: 'element-ui',component: ElementUI},{path: '/',name: 'home',component: HomeView},{path: '/about',name: 'about',// route level code-splitting// this generates a separate chunk (about.[hash].js) for this route// which is lazy-loaded when the route is visited.component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')}
]const router = new VueRouter({mode: 'history',base: process.env.BASE_URL,routes
})export default router

2、crud-update.vue代码

<script>
import axios from "axios";
import pagePath from "@/components/PagePath.vue";const BASE_URL = 'http://localhost:8081/book/'export default {name: 'crud_update',created() {let _this = this;axios.get(BASE_URL + 'findById/' + this.$route.query.bookid).then(resp => {console.log(resp.data)_this.book = resp.data})},data() {return {book: {bookid: 0,name: '',price: 0,},rules: {name: [{required: true, message: '请输入名称', trigger: 'blur'},{min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur'}],}}},methods: {submitForm(book) {let _this = this//这个是全局的this.$refs[book].validate((valid) => {if (valid) {console.log(this.book);axios.put(BASE_URL + 'update', this.book).then(resp => {if (resp.data) {_this.$alert('《' + _this.book.name + '》修改成功', '提示', {confirmButtonText: '确定',callback: action => {_this.$router.push(pagePath.crud_query_delete)}});}})} else {console.log('error submit!!');return false;}});},},
}</script><template><div class="el_update_root"><el-form ref="form" :model="book" label-width="80px" :rules="rules"><el-form-item label="编号" prop="bookid" :rules="[{required:true, message:'id不能为空'},{type:'number', message: 'id必须为数字'}]"><!--        编号不能修改,只读     --><el-input v-model.number="book.bookid" readonly/></el-form-item><el-form-item label="名称" prop="name"><el-input v-model="book.name" placeholder="请输入名称"/></el-form-item><el-form-item label="价格" prop="price" :rules="[{required:true, message:'价格不能为空'},{type:'number', message: '价格必须为数字'}]"><el-input v-model.number="book.price" placeholder="请输入价格"/></el-form-item><el-form-item><el-button type="primary" @click="submitForm('form')">提交</el-button><el-button>取消</el-button></el-form-item></el-form></div></template><style>
.el_update_root {margin-left: 300px;margin-right: 300px;text-align: left;display: flex;justify-content: center;
}</style>

3、crud_insert.vue代码

<script>
import axios from "axios";
import pagePath from "@/components/PagePath.vue"
const BASE_URL = 'http://localhost:8081/book/'export default {name: 'crud_insert',data() {return {book: {bookid: '',name: '',price: '',},rules: {name: [{required: true, message: '请输入名称', trigger: 'blur'},{min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur'}],}}},methods: {submitForm(book) {let _this = this//这个是全局的this.$refs[book].validate((valid) => {if (valid) {console.log(this.book);axios.post(BASE_URL + 'add', this.book).then(resp => {if (resp.data) {_this.$alert('《' + _this.book.name + '》添加成功', '提示', {confirmButtonText: '确定',callback: action => {_this.$router.push(pagePath.crud_query_delete)}});}})} else {console.log('error submit!!');return false;}});},},
}</script><template><div class="el_insert_root"><el-form ref="form" :model="book" label-width="80px" :rules="rules"><el-form-item label="编号" prop="bookid" :rules="[{required:true, message:'id不能为空'},{type:'number', message: 'id必须为数字'}]"><!--        编号不能修改,只读     --><el-input v-model.number="book.bookid" placeholder="请输入编号"/></el-form-item><el-form-item label="名称" prop="name"><el-input v-model="book.name" placeholder="请输入名称"/></el-form-item><el-form-item label="价格" prop="price" :rules="[{required:true, message:'价格不能为空'},{type:'number', message: '价格必须为数字'}]"><el-input v-model.number="book.price" placeholder="请输入价格"/></el-form-item><el-form-item><el-button type="primary" @click="submitForm('form')">提交</el-button><el-button>取消</el-button></el-form-item></el-form></div></template><style>
.el_insert_root {margin-left: 300px;margin-right: 300px;text-align: left;display: flex;justify-content: center;
}</style>

以上就是Element UI+Spring Boot进行CRUD的实例全部内容讲解。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/667464.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

BLIP2——采用Q-Former融合视觉语义与LLM能力的方法

BLIP2——采用Q-Former融合视觉语义与LLM能力的方法 FesianXu 20240202 at Baidu Search Team 前言 大规模语言模型&#xff08;Large Language Model,LLM&#xff09;是当前的当红炸子鸡&#xff0c;展现出了强大的逻辑推理&#xff0c;语义理解能力&#xff0c;而视觉作为人…

YOLOv8进阶 | 如何用yolov8训练自己的数据集(以安全帽佩戴检测举例)

前言&#xff1a;Hello大家好&#xff0c;我是小哥谈。YOLOv8是一种目标检测算法&#xff0c;它是YOLO&#xff08;You Only Look Once&#xff09;系列算法的最新版本。本节课就带领大家如何基于YOLOv8来训练自己的目标检测模型&#xff0c;本次作者就以安全帽佩戴检测为案例进…

华为机考入门python3--(7)牛客7-取近似值

分类&#xff1a;数字 知识点&#xff1a; str转float float(str) 向上取整 math.ceil(float_num) 向下取整 math.floor(float_num) 题目来自【牛客】 import math def round_to_int(float_num): # 如果小数点后的数值大于等于0.5&#xff0c;则向上取整&#xf…

虚拟机克隆的三种方式:全量克隆、快速全量克隆、链接克隆

虚拟机克隆的三种方式:全量克隆、快速全量克隆、链接克隆 快速全量克隆 特点&#xff1a;虚拟机启动快、拍平后数据独立 场景&#xff1a;快速发放独立的虚拟机&#xff0c;减少等待虚拟机部署完成时间&#xff0c;能够快速提供用户使用虚拟机。 实现方式&#xff1a;通过对…

Fink CDC数据同步(一)环境部署

1 背景介绍 Apache Flink 是一个框架和分布式处理引擎&#xff0c;用于在无边界和有边界数据流上进行有状态的计算。Flink 能在所有常见集群环境中运行&#xff0c;并能以内存速度和任意规模进行计算。 Flink CDC 是 Apache Flink 的一组源连接器&#xff0c;基于数据库日志的…

【SpringBoot】RBAC权限控制

&#x1f4dd;个页人主&#xff1a;五敷有你 &#x1f525;系列专栏&#xff1a;SpringBoot⛺️稳重求进&#xff0c;晒太阳 权限系统与RBAC模型 权限 为了解决用户和资源的操作关系&#xff0c; 让指定的用户&#xff0c;只能操作指定的资源。 权限功能 菜单权限&a…

windows下安装go

下载golang Go 官网下载地址&#xff1a; https://golang.org/dl/ Go 官方镜像站&#xff08;推荐&#xff09;&#xff1a; https://golang.google.cn/dl/ 选择安装包 验证有没有安装成功 查看 go 环境 说明 &#xff1a; Go1.11 版本之后无需手动配置环境变量&#xff0c…

29 python快速上手

Python操作MySQL和实战 1. 事务1.1 MySQL客户端1.2 Python代码 2. 锁2.1 排它锁2.2 共享锁 3. 数据库连接池4. SQL工具类4.1 单例和方法4.2 上下文管理 5.其他总结 目标&#xff1a;掌握事务和锁以及Python操作MySQL的各种开发必备知识。 概要&#xff1a; 事务锁数据库连接池…

Weblogic反序列化漏洞分析之CVE-2021-2394

目录 简介 前置知识 Serializable示例 Externalizable示例 联系weblogic ExternalizableLite接口 ExternalizableHelperl类 JdbcRowSetImpl类 MethodAttributeAccessor类 AbstractExtractor类 FilterExtractor类 TopNAggregator$PartialResult类 SortedBag$Wrappe…

【测试运维】web自动化全知识点笔记第1篇:什么是Web自动化测试(已分享,附代码)

本系列文章md笔记&#xff08;已分享&#xff09;主要讨论Web自动化测试相关知识。了解什么是自动化&#xff0c;理解什么是自动化测试以及为什么要使用自动化测试。具体包含&#xff1a;WebDriver的基本操作&#xff0c;WebDriver的鼠标、键盘操作&#xff0c;下拉选择框、警告…

SpringBoot RestTemplate 上传文件

SpringBoot RestTemplate 上传文件 Testpublic void testUpload() throws Exception {String url "http://127.0.0.1/file/upload";String filePath "C:\\temp\\1.png";RestTemplate rest new RestTemplate();FileSystemResource resource new FileSys…

【教学类-46-01】吉祥字门贴1.0(华光通心圆_CNKI 文本框 空心字涂色,最好繁体字)

作品展示 背景需求&#xff1a; 马上就要过年了&#xff0c;家家户户大门上贴上对联和福字 我想用正方形红色手工纸&#xff08;15CM&#xff09;也做一个幼儿描线版的福字 问题一&#xff1a;福字顺时针旋转45度 打印纸上制作福字&#xff0c;需要让这个字顺时针旋转45度&am…

C语言:简单排序

题目描述 输入11个整数&#xff0c;如果第1个数为1&#xff0c;则将其中的第2至11个数升序排列&#xff1b;如果第1个数为0&#xff0c;则降序排列。 输入格式 输入一行&#xff0c;包含11个整数&#xff0c;用空格符分隔。 输出格式 输出1行&#xff0c;包含10个顺序排列的整…

Qt程序设计-使用QSplashScreen制作开机界面

目录 QSplashScreen简介 实例演示 QSplashScreen简介 在Qt中,QSplashScreen类就是用来创建启动画面的。它是一个窗口类,可以显示一个图片,并在图片上显示一些文本信息。QSplashScreen类提供了一些方法,可以方便地设置启动画面的图片和文本,以及控制启动画面的显示和隐藏…

【C++栈和队列:数据结构中的经典组合,高效处理先进先出与后进先出问题的最佳方案】

[本节目标] 1. stack的介绍和使用 2. queue的介绍和使用 3. priority_queue的介绍和使用 4. 容器适配器 1. stack的介绍和使用 1.1 stack的介绍 1. stack是一种容器适配器&#xff0c;专门用在具有后进先出操作的上下文环境中&#xff0c;其删除只能从容器的一端进行元素的…

【DC渗透系列】DC-2靶场

arp先扫 ┌──(root㉿kali)-[~] └─# arp-scan -l Interface: eth0, type: EN10MB, MAC: 00:0c:29:6b:ed:27, IPv4: 192.168.100.251 Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan) 192.168.100.1 00:50:56:c0:00:08 VMware, In…

DolphinScheduler实现隔几天调度

1.场景分析 dolphinscheduler&#xff08;海豚&#xff09;定时器模块-定时调度时每3秒|每3分钟|每3天这种定时&#xff0c;不能够跨分钟&#xff0c;跨小时&#xff0c;跨月&#xff0c;每次跨月等都会从每个月的第1天&#xff08;第几天开始可以设定&#xff09;开始重新计时…

Unity3d Cinemachine篇(四)— StateDrivenCamera

文章目录 前言使用StateDrivenCamera根据不同动画切换相机1. 创建一个游戏物体2. 创建StateDrivenCamera相机3. 创建动画4. 设置相机5. 完成 前言 上一期我们简单的使用了FreeLook相机&#xff0c;这次我们来使用一下StateDrivenCamera 使用StateDrivenCamera根据不同动画切换…

PFMEA的具体实施步骤都有哪些——FMEA软件免费

免费试用FMEA软件-免费版-SunFMEA 一、引言 PFMEA&#xff08;Process Failure Mode and Effects Analysis&#xff09;是一种用于识别、评估和优先处理生产过程中潜在失效模式的工具。它通过对生产过程中的各个环节进行深入分析&#xff0c;发现可能导致产品不合格、过程不稳…

docker maven插件使用介绍

1、配置docker连接 开放docker tcp连接参考本专栏下令一篇文章 2、docker service窗口 3、根据dockerfile 构建镜像 注意 idea 用通过管理员身份启动&#xff0c;否则连不上docker 构建前添加maven goal 打包 4、运行镜像 创建容器 5、运行docker compose 报错 需要先配置d…