springboot+vue开发后台增删改查

效果图

80901afefd1e4a47aad146de186ff807.png

3c4004dde4d34fc1a38a4b4263796ad8.png

前端代码【User.vue】

<template>
  <div class="data-container">
    <!--添加 start-->
    <div class="data-header">
      <el-button round @click="addHander" size="large" type="primary">
        <el-icon>
          <DocumentAdd/>
        </el-icon>
        <span>新增</span>
      </el-button>
    </div>
    <!--添加 end-->
    <!--表格数据展示 start-->
    <div class="data-table">
      <el-table :data="dataList.list" style="width: 1200px;">
        <el-table-column label="头像" prop="userImg" align="center">
          <template #default="scope">
            <img :src="scope.row.userImg" style="height:60px"/>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="昵称" prop="nickname" align="center"
                         width="120"></el-table-column>
        <el-table-column label="账号" prop="username" align="center" width="140"></el-table-column>
        <el-table-column label="手机号" prop="phone" align="center" width="140"></el-table-column>
        <el-table-column show-overflow-tooltip label="邮箱" prop="email" align="center" width="160"></el-table-column>
        <el-table-column label="性别" prop="userSex" align="center" width="60"></el-table-column>
        <el-table-column label="状态" prop="userStatus" align="center">
          <template #default="scope">
            <el-tag round :type="scope.row.userStatus == '1' ? 'success' : 'info'">
              {{ scope.row.userStatus == '1' ? '激活' : '未激活' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="个性签名" prop="signature" align="center"></el-table-column>
        <el-table-column show-overflow-tooltip label="自我介绍" prop="userIntroduce" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="220">
          <template #default="scope">
            <el-button size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="small" type="primary" @click="handleStatus(scope.$index, scope.row)">修改状态</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页 start-->
      <div class="page">
        <el-pagination background
                       layout="prev,pager,next,jumper"
                       :default-page-size="defaultPageSize"
                       :total="totalData"
                       @current-change="currentChangeHaddler"></el-pagination>
      </div>
      <!--分页 end-->
    </div>
    <!--表格数据展示 end-->
    <!--添加对话框 start-->
    <el-dialog draggable destroy-on-close v-model="dialogAddVisible" title="添加" width="70%" center>
      <el-form inline :model="addFormInfo" label-width="150px">
        <el-form-item label="头像">
          <el-input v-model="addFormInfo.userImg"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="addFormInfo.nickname"></el-input>
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="addFormInfo.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="addFormInfo.password"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="addFormInfo.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="addFormInfo.email"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="addFormInfo.userSex"></el-input>
        </el-form-item>
        <el-form-item label="个性签名">
          <el-input type="textarea" rows="3" style="width: 800px" v-model="addFormInfo.signature"></el-input>
        </el-form-item>
        <el-form-item label="自我介绍">
          <el-input type="textarea" rows="6" style="width: 800px" v-model="addFormInfo.userIntroduce"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogAddVisible = false">取消</el-button>
                <el-button type="primary" @click="sureHandler">确定</el-button>
            </span>
      </template>
    </el-dialog>
    <!--添加对话框 end-->
    <!--编辑对话框 start-->
    <!--destroy-on-close:每次关闭对话框时直接销毁对话框,没有缓存-->
    <el-dialog
        draggable
        destroy-on-close
        v-model="dialogEditorVisible"
        title="编辑"
        width="70%"
        center>
      <el-form inline :model="editorFormInfo" label-width="150px">
        <el-form-item label="头像">
          <el-input v-model="editorFormInfo.userImg"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="editorFormInfo.nickname"></el-input>
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="editorFormInfo.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="editorFormInfo.password"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="editorFormInfo.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="editorFormInfo.email"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="editorFormInfo.userSex"></el-input>
        </el-form-item>
        <el-form-item label="个性签名">
          <el-input type="textarea" rows="3" style="width: 800px" v-model="editorFormInfo.signature"></el-input>
        </el-form-item>
        <el-form-item label="自我介绍">
          <el-input type="textarea" rows="6" style="width: 800px" v-model="editorFormInfo.userIntroduce"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogEditorVisible = false">取消</el-button>
                <el-button type="primary" @click="sureEditorHandler">确定</el-button>
            </span>
      </template>
    </el-dialog>
    <!--编辑对话框 end-->
  </div>
</template>

<script setup>
import axios from "@/utils/request.js"
import {onMounted, reactive, ref} from "vue";
import {ElMessage} from "element-plus";
//初始化分页查询数据
const dataList = reactive({
  list: []
})
//初始化总条数
const totalData = ref(0)
//当前页
const currentPage = ref(1)
//初始化分页显示条数
const defaultPageSize = ref(10)
//添加添加对话框控制器
const dialogAddVisible = ref(false)
//初始化添加对话框状态
const addFormInfo = reactive({
  userImg: '',
  nickname: '',
  username: '',
  password: '',
  phone: '',
  email: '',
  userSex: '',
  signature: '',
  userIntroduce: '',
  userStatus: '1',
})
//编辑对话框控制器
const dialogEditorVisible = ref(false)
//初始化编辑对话框状态
const editorFormInfo = reactive({
  userId: '',
  userImg: '',
  nickname: '',
  username: '',
  password: '',
  phone: '',
  email: '',
  userSex: '',
  signature: '',
  userIntroduce: '',
  userStatus: '',
})
/**
 * 网路请求:分页查询
 *  */
const http = (page, size) => {
  axios.get('user/search', {
    params: {
      page: page,
      size: size
    }
  }).then(res => {
    if (res.data.code == 200) {
      dataList.list = res.data.data.records
      totalData.value = res.data.data.total
    } else {
      ElMessage.error(res.data.message)
    }

  })
}
onMounted(() => {
  http(currentPage.value, defaultPageSize.value)
})
/**
 * 分页
 */
const currentChangeHaddler = (nowPage) => {
  http(nowPage, defaultPageSize.value)
  currentPage.value = nowPage
}
/**
 * 添加对话框弹出事件
 */
const addHander = () => {
  dialogAddVisible.value = true
}
/**
 * 添加对话框 确定事件
 */
const sureHandler = () => {
  axios.post('user/add', {
    userImg: addFormInfo.userImg,
    nickname: addFormInfo.nickname,
    username: addFormInfo.username,
    password: addFormInfo.password,
    phone: addFormInfo.phone,
    email: addFormInfo.email,
    userSex: addFormInfo.userSex,
    signature: addFormInfo.signature,
    userIntroduce: addFormInfo.userIntroduce,
    userStatus: addFormInfo.userStatus,
  }).then(res => {
    if (res.data.code == 200) {
      dialogAddVisible.value = false
      http(currentPage.value, defaultPageSize.value)
    } else {
      ElMessage.error(res.data.message)
    }
  })
}
/**
 * 编辑对话框 弹出事件
 *  */
const handleEdit = (index, row) => {

  dialogEditorVisible.value = true
  axios.get('user/findById', {
    params: {
      userId: row.userId
    }
  }).then(res => {

    if (res.data.code == 200) {
      editorFormInfo.userId = res.data.data.userId;
      editorFormInfo.userImg = res.data.data.userImg;
      editorFormInfo.nickname = res.data.data.nickname;
      editorFormInfo.username = res.data.data.username;
      editorFormInfo.password = res.data.data.password;
      editorFormInfo.phone = res.data.data.phone;
      editorFormInfo.email = res.data.data.email;
      editorFormInfo.userSex = res.data.data.userSex;
      editorFormInfo.signature = res.data.data.signature;
      editorFormInfo.userIntroduce = res.data.data.userIntroduce;
      editorFormInfo.userStatus = res.data.data.userStatus;
    } else {
      ElMessage.error(res.data.data.message)
    }
  })

}
/**
 * 编辑对话框 确定事件
 */
const sureEditorHandler = () => {
  axios.post('user/update', {
    userId: editorFormInfo.userId,
    userImg: editorFormInfo.userImg,
    nickname: editorFormInfo.nickname,
    username: editorFormInfo.username,
    password: editorFormInfo.password,
    phone: editorFormInfo.phone,
    email: editorFormInfo.email,
    userSex: editorFormInfo.userSex,
    signature: editorFormInfo.signature,
    userIntroduce: editorFormInfo.userIntroduce,
    userStatus: editorFormInfo.userStatus,
  }).then(res => {
    if (res.data.code == 200) {
      dialogEditorVisible.value = false
      http(currentPage.value, defaultPageSize.value)
    } else {
      //添加失败:给出提示信息(element-plus/反馈组件/message信息提示)
      ElMessage.error(res.data.message)
    }
  })
}
/**删除 */
const handleDelete = (index, row) => {
  ElMessageBox.confirm(
      '确定删除么',
      '删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  ).then(() => {
    //确认删除
    axios.delete("user/delete", {
      params: {
        userId: row.userId
      }
    }).then(res => {
      if (res.data.code == 200) {
        ElMessage({
          type: 'success',
          message: "删除成功!!!",
        })
        //刷新
        http(currentPage.value, defaultPageSize.value)
      } else {
        ElMessage({
          type: 'error',
          message: res.data.message,
        })
      }
    })
  }).catch(error => {
    ElMessage({
      type: 'info',
      message: "取消删除",
    })
  })
}
/**
 * 修改用户状态
 */
const handleStatus = (index, row) => {
  axios.post("user/updateStatus", {userId: row.userId}).
      then(res=>{
        if(res.data.code==200){
          ElMessage.success("状态已更改")
          http(currentPage.value, defaultPageSize.value)
        }
  })
}
</script>
<style scoped>
.data-container {
  background: linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
  background: -o-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
  background: -ms-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
  background: -moz-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
  background: -webkit-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
  height: 800px;
}

.data-header {
  padding: 20px;
}

.data-table {
  padding: 20px;
}

.page {
  position: fixed;
  right: 10px;
  bottom: 10px;
}
</style>

后端代码【java】

实体类

package jkw.pojo;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;

/**
 * 用户
 */
@Data
public class User implements Serializable {
    @TableId
    private Integer userId;

    private String userImg; // 头像
    private String nickname; // 昵称

    private String username; // 账号
    private String password; // 密码
    private String phone; // 手机号

    private String email;//邮箱
    private String userSex; // 性别
    private String signature;//个性签名
    private String userIntroduce;//自我介绍

    private String userStatus; // 用户状态(1激活 0未激活)

}

mapper

package jkw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jkw.pojo.User;

public interface UserMapper extends BaseMapper<User> {
}

service

package jkw.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.User;

public interface UserService {
    void add(User user);
    void update(User user);
    void delete(Integer id);
    User findById(Integer id);
    Page<User> search(int page,int size);
    void updateStatus(Integer id);
}

serviceImpl

package jkw.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.mapper.UserMapper;
import jkw.pojo.User;
import jkw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void delete(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public Page<User> search(int page, int size) {
        return userMapper.selectPage(new Page<>(page, size), null);
    }

    @Override
    public void updateStatus(Integer id) {
        User user = userMapper.selectById(id);
        if(user.getUserStatus().equals("1")){
            user.setUserStatus("0");
            userMapper.updateById(user);
        }else {
            user.setUserStatus("1");
            userMapper.updateById(user);
        }
    }
}

controller

package jkw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.User;
import jkw.service.UserService;
import jkw.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("/user")
@RestController
public class UserCon {
    @Autowired
    private UserService userService;

    /**
     * 新增
     *
     * @param user
     * @return
     */
    @PostMapping("/add")
    //@PreAuthorize("hasAnyAuthority('/user')")
    public BaseResult add(User user) {
        userService.add(user);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param user
     * @return
     */
    @PostMapping("/update")
    public BaseResult update(User user) {
        userService.update(user);
        return BaseResult.ok();
    }

    /**
     * 删除
     *
     * @param userId
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Integer userId) {
        userService.delete(userId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询
     *
     * @param userId
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer userId) {
        User user = userService.findById(userId);
        return BaseResult.ok(user);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */

    @GetMapping("/search")
    //@PreAuthorize("hasAnyAuthority('/user')")
    public BaseResult search(int page, int size) {
        Page<User> brandPage = userService.search(page, size);
        return BaseResult.ok(brandPage);
    }

    /**
     * 修改状态
     * @param userId
     * @return
     */
    @PostMapping("/updateStatus")
    public BaseResult updateStatus(Integer userId) {
        userService.updateStatus(userId);
        return BaseResult.ok();
    }
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

区间预测 | MATLAB实现QRBiLSTM双向长短期记忆神经网络分位数回归多输入单输出区间预测

区间预测 | MATLAB实现QRBiLSTM双向长短期记忆神经网络分位数回归多输入单输出区间预测 目录 区间预测 | MATLAB实现QRBiLSTM双向长短期记忆神经网络分位数回归多输入单输出区间预测效果一览基本介绍模型描述程序设计参考资料 效果一览 基本介绍 区间预测 | MATLAB实现QRBiLSTM…

uview中的常用的框

第一步&#xff1a; 先下载 uview UI 框架 详见 项目 引入 uView_vue引入uview_qq_2524963996的博客-CSDN博客【代码】 项目 引入 uView。_vue引入uviewhttps://blog.csdn.net/qq_44161703/article/details/131168976?spm1001.2014.3001.5501 第二步&#xff1a; 可以直接…

解锁潜力,驭数赋能:大数据与云计算的强强联合

随着数字化时代的来临&#xff0c;大数据和云计算已成为信息技术领域的两大热门话题。大数据指的是以海量、高速、多样化的数据为基础&#xff0c;通过分析和挖掘来获得有价值的信息和洞察。而云计算则是一种基于网络的计算模式&#xff0c;通过将数据和应用程序存储在云端服务…

【前端动画】科技感扫描效果 css动画animation

扫描出现动画 参考了网友写的二维码扫描 <template><div><div class"scan-content"><img style"width: 2rem;height: 2rem;" src"../../assets/images/eye.png" alt"" /><div class"line">…

Express 框架的基本操作

目录 1、应用生成器 2、基本路由 2.1、在跟路由下配置 GET请求&#xff0c;返回对应相应内容。 2.2、在跟路由下配置 POST请求&#xff0c;返回对应相应内容。 2.3、在跟路由下配置 PUT请求&#xff0c;返回对应相应内容。 2.4、在根路由下配置DELETE请求&#xff0c;返回对…

<Java物联网> 从主动到被动:Java中的BACnet设备属性查询

目录 BACnet 使用软件 资源 模拟器 使用Java主动查 引入maven 创建网络对象 获取远程设备 获取设备属性 使用DeviceEventAdapter订阅 初始化本地BACnet设备和IP网络配置&#xff1a; 启动本地设备和添加监听器&#xff1a; 搜寻远程设备&#xff1a; 发送订阅COV报…

mybatis事物是如何和spring事物整合的

目录 1、mybatis事物管理器 2、SpringManagedTransactionFactory如何处理事物 3、spring事物如何设置connection连接到threadLocal 1、mybatis事物管理器 mybatis事物抽象接口类&#xff1a;Transaction。该接口定义了事物基本方法和获取数据库连接方法 该类有三个实现类Jd…

基于Java+SpringBoot+Vue前后端分离旅游网站详细设计和实现

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

pytorch工具——使用pytorch构建一个分类器

目录 分类器任务和数据介绍训练分类器的步骤在GPU上训练模型 分类器任务和数据介绍 训练分类器的步骤 #1 import torch import torchvision import torchvision.transforms as transformstransformtransforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,0.5,0.…

docker数据网络管理

数据管理 管理 Docker 容器中数据主要有两种方式&#xff1a;数据卷&#xff08;Data Volumes&#xff09;和数据卷容器&#xff08;DataVolumes Containers&#xff09;。 1&#xff0e;数据卷 数据卷是一个供容器使用的特殊目录&#xff0c;位于容器中。可将宿主机的目录挂…

详细解析python视频选择--【思维导图知识范围】

C ,JAVA JAVAWEB ,微信小程序等 都有视频选择的分析。 语言视频选择收录专辑链接C张雪峰推荐选择了计算机专业之后-在大学期间卷起来-【大学生活篇】JAVA黑马B站视频JAVA部分的知识范围、学习步骤详解JAVAWEB黑马B站视频JAVAWEB部分的知识范围、学习步骤详解SpringBootSpringB…

Qt/C++音视频开发48-推流到rtsp服务器

一、前言 之前已经打通了rtmp的推流&#xff0c;理论上按照同样的代码&#xff0c;只要将rtmp推流地址换成rtsp推流地址&#xff0c;然后格式将flv换成rtsp就行&#xff0c;无奈直接遇到协议不支持的错误提示&#xff0c;网上说要换成rtp&#xff0c;换了也没用&#xff0c;而…

斯坦福数据挖掘教程·第三版》读书笔记(英文版)Chapter 13 Neural Nets and Deep Learning

来源&#xff1a;《斯坦福数据挖掘教程第三版》对应的公开英文书和PPT Chapter 13 Neural Nets and Deep Learning In this chapter, we shall consider the design of neural nets, which are collections of perceptrons, or nodes, where the outputs of one rank (or lay…

使用 Docker 快速上手中文版 LLaMA2 开源大模型

本篇文章&#xff0c;我们聊聊如何使用 Docker 容器快速上手朋友团队出品的中文版 LLaMA2 开源大模型&#xff0c;国内第一个真正开源&#xff0c;可以运行、下载、私有部署&#xff0c;并且支持商业使用。 写在前面 感慨于昨天 Meta LLaMA2 模型开放下载之后&#xff0c;Git…

Spring Security 的工作原理/总体架构

目录 1、过滤器的视角 2、DelegatingFilterProxy 委派过滤器代理&#xff08;类&#xff09; 2、FilterChainProxy 过滤器链代理&#xff08;类&#xff09; 4、SecurityFilterChain 安全过滤器链&#xff08;接口&#xff09; 5、Security Filters 安全过滤器实例 6、Sp…

基于sklearn计算precision、recall等分类指标

文章目录 一、分类指标函数1.1 precision_score函数1.2 recall_score函数1.3 accuracy_score函数1.4 f1_score函数1.5 precision_recall_curve函数1.6 roc_curve函数1.7 roc_auc_score函数1.8 classification_report函数 二、二分类任务三、多分类任务3.1 Macro Average&#x…

Meta牵手Microsoft推出下一代Llama 2

官方消息 1、今天&#xff0c;我们将介绍 Llama 2 的可用性&#xff0c;这是我们的下一代开源大型语言模型。 2、Llama 2免费用于研究和商业用途。 3、Microsoft和 Meta 正在扩大他们的长期合作伙伴关系&#xff0c;Microsoft 是 Llama 2 的首选合作伙伴。 4、在技术、学术…

力扣 -- 122. 买卖股票的最佳时机 II

一、题目&#xff1a; 题目链接&#xff1a;122. 买卖股票的最佳时机 II - 力扣&#xff08;LeetCode&#xff09; 二、解题步骤 下面是用动态规划的思想解决这道题的过程&#xff0c;相信各位小伙伴都能看懂并且掌握这道经典的动规题目滴。 三、参考代码&#xff1a; clas…

Xcode 15 beta 4 (15A5195m) - Apple 平台 IDE

Xcode 15 beta 4 (15A5195m) - Apple 平台 IDE IDE for iOS/iPadOS/macOS/watchOS/tvOS/visonOS 请访问原文链接&#xff1a;https://sysin.org/blog/apple-xcode-15/&#xff0c;查看最新版。原创作品&#xff0c;转载请保留出处。 作者主页&#xff1a;sysin.org visonOS …

基于ESP32-S3-BOX-Lite的语音合成与播报系统(esp-idf+WiFi+HTTPS+TTS)

目录 项目介绍硬件介绍项目设计开发环境及工程目录总体流程图硬件初始化WiFiHTTPS请求TTS语音合成与播报cJSON解析TTS初始化语音合成与播报 附加功能按键回调LVGL数据可视化显示 功能展示项目总结 &#x1f449; 【Funpack2-5】基于ESP32-S3-BOX-Lite的语音合成与播报系统 &…