Element UI+Spring Boot进行CRUD的实例

news2024/10/7 20:26:48

ElementUI安装与使用指南

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

后端代码:点击查看 LearnElementUiAndSpringBoot

一、前端配置

安装axios

  • Gitee的axios介绍与使用

  • GitHub的axios介绍与使用

  • 方式一:使用npm安装

    $ npm install axios
    在这里插入图片描述

  • 方式二:用 bower:

    $ bower install axios

  • 方式三:使用 cdn方式

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

二、后端配置

  • 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.coloradmin.cn/o/1433328.html

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

相关文章

2024年最新幻兽帕鲁服务器搭建教程

玩转幻兽帕鲁服务器&#xff0c;阿里云推出新手0基础一键部署幻兽帕鲁服务器教程&#xff0c;傻瓜式一键部署&#xff0c;3分钟即可成功创建一台Palworld专属服务器&#xff0c;成本仅需26元&#xff0c;阿里云服务器网aliyunfuwuqi.com分享2024年新版基于阿里云搭建幻兽帕鲁服…

回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制)

回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&#xff09; 目录 回归预测 | Matlab实现WOA-CNN-LSTM-Attention鲸鱼算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&…

谷歌产品大更新:Bard可生成图像;文生音乐平台等5大免费功能

2月2日&#xff0c;谷歌在官网对生成式AI产品进行了大更新&#xff0c;包括类ChatGPT聊天助手Bard可以通过文本提示生成图像&#xff1b; 全新的文生音乐平台MusicFX&#xff1b;新的文生图像平台ImageFX&#xff1b;新的文本扩写平台TextFX&#xff1b;在谷歌地图中增加生成式…

docker搭建Mysql集群准备(一)

docker搭建Mysql集群准备 Linux基本知识&#xff1a; 修改机器 IP&#xff0c;变成静态 IP vim /etc/sysconfig/network-scripts/ifcfg-ens33 文件 TYPEEthernet PROXY_METHODnone BROWSER_ONLYno BOOTPROTOstatic IPADDR192.168.190.67 NETMASK255.255.255.0 GAT…

第六讲:文件操作

第六讲:文件操作 文件夹创建文件夹移动文件夹复制文件夹删除文件夹文件操作文件读取文件写入文件文件夹 创建文件夹 定义创建文件夹函数:chmk_path()定义一个函数 chmk_path(),这个函数的功能是创建文件夹。 首先需要导入操作系统接口模块——os 模块,这个模块中包含某些函…

802.11n 802.11ac (WiFi 4/5 )的核心要点

802.11n 802.11ac &#xff08;WiFi 4/5 &#xff09;是什么&#xff1f; WiFi 4&#xff1a; Ieee 802.11n Enhancements for High Throughput &#xff08;HT&#xff09; WiFi 5&#xff1a; Ieee 802.11ac Enhancements for Very High Throughput &#xff08;VHT&#x…

ywtool login guard命令

一.登录防护功能介绍 登录防护功能主要检查系统日志/var/log/secure&#xff0c;查看系统有没有被暴力登录。登录防护默认是检测3分钟内登录系统失败15次(次数可修改)后,视其为有攻击性,拉黑此IP(centos7通过系统文件阻止IP,centos8/9通过防火墙阻止IP)。此脚本只针对SSH访问,…

vscode 无法远程连接waiting the server log

使用版本 报错信息 相关日志 [17:32:59.765] > Waiting for server log... [17:32:59.801] > Waiting for server log... [17:32:59.831] > > * > * Visual Studio Code Server > * > * By using the software, you agree to > * the Visual Studio…

浅压缩、深压缩、双引擎、计算机屏幕编码……何去何从?

专业视听领域尤其显示控制和坐席控制领域&#xff0c;最近几年最激动人心的技术&#xff0c;莫过于分布式了。 分布式从推出之日就备受关注&#xff1a;担心稳定性的&#xff0c;质疑同步性能的&#xff0c;怀疑画面质量的…… 诚然&#xff0c;我们在此前见多了带着马赛克的…

Rust 本地文档的使用:rustup doc

Rust 是一种系统级编程语言&#xff0c;以其安全性、速度和内存控制能力而闻名。为了方便开发者更好地了解并利用 Rust 标准库和工具链中的功能&#xff0c;Rust 提供了一种内置的文档浏览方式——通过 rustup doc 命令。 安装 rustup 在查阅 Rust 文档之前&#xff0c;确保你…

Photoshop插件来了#comfyui-mixlab-ps-plugin

今天有用户向我反馈&#xff0c;提出ps是设计师最习惯的工具&#xff0c;问我可不可以开发个ps的插件&#xff1f; 我纠结了下&#xff0c;因为从来没有开发过ps插件&#xff0c;想着应该上手会比较耗时间&#xff0c;不过耗时这个问题&#xff0c;最近在用MixCopilot辅助编程&…

LabVIEW与EtherCAT实现风洞安全联锁及状态监测

LabVIEW与EtherCAT实现风洞安全联锁及状态监测 在现代风洞试验中&#xff0c;安全联锁与状态监测系统发挥着至关重要的作用&#xff0c;确保了试验过程的安全性与高效性。介绍了一套基于EtherCAT总线技术和LabVIEW软件开发的风洞安全联锁及状态监测系统。该系统通过实时、可靠…

vuecli3 执行 npm run build 打包命令报错:TypeError: file.split is not a function

问题 今天有个项目在打包的时候遇到了一个问题&#xff0c;就是执行 npm run build 命令的时候报错了&#xff0c;如下&#xff1a; 解决 我排查了一下&#xff0c;模拟代码如下&#xff1a;在打包的时候用了 MinChunkSizePlugin const webpack require("webpack"…

pwn学习笔记(2)

pwn学习笔记&#xff08;2&#xff09; 1.三种常见的寄存器&#xff1a; ​ ax寄存器&#xff1a;通用寄存器&#xff0c;可用于存放多种数据 ​ bp寄存器&#xff1a;存放的是栈帧的栈底地址 ​ sp寄存器&#xff1a;存放的是栈顶的地址 2.栈帧与栈工作的简介&#xff1a…

小白水平理解面试经典题目_数组类LeetCode 118 Pascal‘s Triangle【回归解法】

LeetCode 118 生成杨辉三角&#xff08;Pascal’s Triangle&#xff09; 小白渣翻译 给定一个非负整数 numRows&#xff0c;生成杨辉三角的前 numRows 行。 在杨辉三角中&#xff0c;每个数是它左上方和右上方的数的和。 例子 这里是小白理解 那么这种题目一上来看&#xf…

SDL库的下载与配置(Visual Studio )2024/2/4更新

一.SDL的下载 下载链接 二.SDL的环境配置 解压以后放在中文路径下 不会添加环境变量自行搜索&#xff08;比较简单网上教程很多&#xff09; 下面进行编译器的配置 复制这段内容 x64\SDL2main.lib x64\SDL2.lib将这段代码放进去运行一下 #include <SDL.h>int main(int…

常用排序算法(Java版本)

1 引言 常见的排序算法有八种&#xff1a;交换排序【冒泡排序、快速排序】、插入排序【直接插入排序、希尔排序】、选择排序【简单选择排序、堆排序】、归并排序、基数排序。 2 交换排序 所谓交换&#xff0c;就是序列中任意两个元素进行比较&#xff0c;根据比较结果来交换…

docker 构建个人博客网站

1、项目地址 https://gitee.com/hhll/blog-hangliang.git 2、打包docker镜像并上传docker hub 【1】注册docker hub账号https://hub.docker.com/ 【2】在docker hub建对应的仓库 【3】登录docker hub并打包上传前后端镜像 sudo docker login -u xxxx 密码 xxxxxx 后端&am…

【Elasticsearch】从入门到精通

目前java常见的针对大数据存储的方案并不多&#xff0c;常见的就是mysql的分库分表、es存储 这里偏向es存储方案&#xff0c;es不同的版本之间其实差异还挺大的&#xff0c;本篇博文版本Elasticsearch 7.14.0 Springboot整合Easy-Es Easy-Es官方文档 Elasticsearch的初步认识 …

Python中的HTTP代理服务器和客户端的区别与联系

在Python编程中&#xff0c;当我们涉及到网络通信&#xff0c;尤其是HTTP请求时&#xff0c;经常会听到“HTTP代理服务器”和“客户端”这两个词。它们在网络世界中扮演着不同的角色&#xff0c;但又有着紧密的联系。 区别 首先&#xff0c;我们来谈谈它们的区别。 HTTP代理…