最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue結(jié)合Springboot實(shí)現(xiàn)用戶(hù)列表單頁(yè)面(前后端分離)

 更新時(shí)間:2021年07月22日 10:28:12   作者:林深時(shí)不見(jiàn)鹿  
本文主要介紹了Vue結(jié)合Springboot實(shí)現(xiàn)用戶(hù)列表單頁(yè)面,可以實(shí)現(xiàn)簡(jiǎn)單的查詢(xún),刪除,修改,和添加用戶(hù)信息功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

用戶(hù)列表頁(yè)面開(kāi)發(fā)

項(xiàng)目介紹

用戶(hù)列表頁(yè)面開(kāi)發(fā),可以實(shí)現(xiàn)簡(jiǎn)單的查詢(xún),刪除,修改,和添加用戶(hù)信息功能。前端使用vue框架,后端使用springboot框架,一個(gè)簡(jiǎn)單的vue+springboot前后端分離小項(xiàng)目。

本項(xiàng)目主要模塊及技術(shù)點(diǎn)如圖

項(xiàng)目源碼+筆記+資料

vue-springboot_jb51.rar

1、前端html頁(yè)面編寫(xiě)

頁(yè)面:

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-NUszDfUe-1626677532963)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210715163139071.jpg)]

代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue系列課程</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet"  rel="external nofollow" >
</head>
<body>
    <div id="app">

        <div class="container-fluid">
            <!--標(biāo)題行-->
            <div class="row">
                <div class="col-sm-6 col-sm-offset-3"><h1 class="text-center">用戶(hù)列表</h1></div>
            </div>
            <!--數(shù)據(jù)行-->
            <div class="row">
                <div class="col-sm-10 col-sm-offset-1">
                    <!--添加按鈕-->
                    <a href="" class=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btn-success btn-sm">添加</a>
                    <!--列表-->
                    <table class="table table-striped table-bordered" style="margin-top: 10px;">
                        <tr>
                            <td>編號(hào)</td>
                            <td>姓名</td>
                            <td>工資</td>
                            <td>年齡</td>
                            <td>個(gè)人簡(jiǎn)介</td>
                            <td>操作</td>
                        </tr>
                        <tr v-for="user in users">
                            <td>{{user.id}}</td>
                            <td>{{user.name}}</td>
                            <td>{{user.salary}}</td>
                            <td>{{user.age}}</td>
                            <td>{{user.description}}</td>
                            <td>
                                <a href="" class=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btn btn-danger btn-sm">刪除</a>
                                <a href="" class=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btn btn-info btn-sm">修改</a>
                            </td>
                        </tr>

                    </table>
                    <!--添加 和 修改表單-->
                    <form>
                        <div class="form-group">
                            <label class="control-label">編號(hào)</label>
                            <div >
                                <p class="form-control-static">0001</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name">姓名</label>
                            <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入姓名">
                        </div>
                        <div class="form-group">
                            <label for="salary">工資</label>
                            <input type="text" class="form-control" id="salary" placeholder="請(qǐng)輸入工資">
                        </div>
                        <div class="form-group">
                            <label for="age">年齡</label>
                            <input type="text" class="form-control" id="age" placeholder="請(qǐng)輸入年齡">
                        </div>
                        <div class="form-group">
                            <label for="description">個(gè)人簡(jiǎn)介</label>
                            <input type="text" class="form-control" id="description" placeholder="請(qǐng)輸入個(gè)人簡(jiǎn)介">
                        </div>

                        <button type="submit" class="btn btn-primary">Submit</button>
                    </form>
                </div>
            </div>
        </div>

    </div>
</body>
</html>
<!--引入axios-->
<script src="js/axios.min.js"></script>
<!--引入vue-->
<script src="js/vue.js"></script>
<script>
    var app = new Vue({
        el: "#app",
        data:{
            msg:"vue 生命周期",
            users:[],
        },
        methods:{

        },
        computed:{

        },
        created(){
            //發(fā)送axios請(qǐng)求
            /*axios.get("http://localhost:8989/users").then(res=>{
               this.users = res.data;
            });*/
            this.users =[{id:1,name:"小陳",age:23,salary:2300,description:"他是一個(gè)小白!!!"}]
        },
    });
</script>

我們將html頁(yè)面放到如下位置:

js目錄下存放vue和axios資源文件。

2、springboot框架搭建

2.1、項(xiàng)目創(chuàng)建

1、新建maven項(xiàng)目,取名為vue_day3_admin

2、引入sprinboot-web依賴(lài)

<dependencies>
    <!--引入springboot-web依賴(lài)-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

3、編寫(xiě)啟動(dòng)類(lèi)AdminApplication

package com.xiao;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class,args);
    }
}

4、測(cè)試

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-RudlBSAU-1626677532964)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210715175029350.jpg)]

2.2、連接數(shù)據(jù)庫(kù)

1、創(chuàng)建vue_day3數(shù)據(jù)庫(kù)

CREATE TABLE t_user(
	id INT(6) PRIMARY KEY AUTO_INCREMENT,
	NAME VARCHAR(40),
	salary DOUBLE(7,2),
	age INT(3),
	des VARCHAR(200)
);

2、引入數(shù)據(jù)庫(kù)相關(guān)依賴(lài)

<!--整合mybatis 引入依賴(lài)-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.3</version>
</dependency>
<!--mysql-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>5.1.38</scope>
</dependency>
<!--druid-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.2.1</version>
</dependency>
</dependencies>

3、application.properties配置文件編寫(xiě)

server.port=8990

# 整合mybatis

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/vue_day3?characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root

# 指定mapper出現(xiàn)的位置
mybatis.mapper-locations=classpath:com/xiao/mapper/*.xml
mybatis.type-aliases-package=com.xiao.entity

# 展示執(zhí)行過(guò)程中sql語(yǔ)句
logging.level.com.xiao.dao=debug

4、springboot連接mysql數(shù)據(jù)庫(kù)

4.1、打開(kāi)Data Sources and Deivers 輸入數(shù)據(jù)庫(kù)user和password,并選擇要連接的數(shù)據(jù)庫(kù)。

4.2、設(shè)置時(shí)區(qū)為UTC

5、啟動(dòng)測(cè)試一下

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-BASB2gjK-1626677532966)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210715201122304.jpg)]

沒(méi)有任何問(wèn)題。

2.3、項(xiàng)目完整依賴(lài)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>vue_day3_admin</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--繼承springboot父項(xiàng)目-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
    </parent>
    <dependencies>
        <!--引入springboot-web依賴(lài)-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--整合mybatis 引入依賴(lài)-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>5.1.38</scope>
        </dependency>
        <!--druid-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.2.1</version>
        </dependency>
        <!--本地測(cè)試-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.5.12.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

3、編寫(xiě)entity層

創(chuàng)建user實(shí)體類(lèi)

package com.xiao.entity;

public class User {
    private Integer id;
    private String name;
    private Double salary;
    private Integer age;
    private String des;

    public User() {
    }

    public User(Integer id, String name, Double salary, Integer age, String des) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.age = age;
        this.des = des;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                ", age=" + age +
                ", des='" + des + '\'' +
                '}';
    }
}

4、查詢(xún)用戶(hù)信息

4.1、后端代碼編寫(xiě)

1、UserDAO編寫(xiě)

package com.xiao.dao;

import com.xiao.entity.User;

import java.util.List;

public interface UserDAO {

    //查詢(xún)所有用戶(hù)信息
    List<User> findAll();
}

2、UserDAOMapper.xml編寫(xiě)

resources下創(chuàng)建如下目錄

****

代碼:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xiao.dao.UserDAO">
    <!--findAll-->
    <select id="findAll" resultType="User">
        select id,name,salary,age,des from t_user;
    </select>
</mapper>

3、service層編寫(xiě)

UserService 接口

package com.xiao.service;

import com.xiao.entity.User;
import java.util.List;

public interface UserService {
    //查詢(xún)所有用戶(hù)方法
    List<User> findAll();
}

UserServiceImpl 實(shí)現(xiàn)類(lèi)

package com.xiao.service;

import com.xiao.dao.UserDAO;
import com.xiao.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service //代表這是一個(gè)業(yè)務(wù)層組件 作用:用來(lái)在spring工廠(chǎng)中創(chuàng)建一個(gè)userServiceImpl對(duì)象
@Transactional //代表給類(lèi)中所有的方法加入事務(wù)控制
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDAO userDAO;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS) //方法上聲明事務(wù)注解
    public List<User> findAll() {
        return userDAO.findAll();
    }
}

4、進(jìn)行test測(cè)試

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-pfLCSqdg-1626677532967)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210716180343384.jpg)]

BasicTest類(lèi)

package com.xiao.test;
import com.xiao.AdminApplication;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = AdminApplication.class) //指定入口類(lèi)@RunWith(SpringRunner.class)  //啟動(dòng)工廠(chǎng)public class BasicTest {}

TestUserService類(lèi)

package com.xiao.test;
import com.xiao.service.UserService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class TestUserService extends BasicTest 
{
    @Autowired private UserService userService;
    @Test public void findAll() {
        userService.findAll().forEach(user -> System.out.println(user));
    }
}

測(cè)試成功?。。?/strong>

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-irJbdJfR-1626677532969)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210716180457334.jpg)]

4.2、前端代碼編寫(xiě)

1、在created()函數(shù)中添加axios請(qǐng)求

# 生命周期鉤子:生命周期函數(shù)
初始化階段
1.beforeCreate vue實(shí)例自身事件生命周期初始化
2.created 完成自定義data methods computed 注入和校驗(yàn) 推薦
3.beforeMount將el指向html編譯為模板,并沒(méi)有完成模板注入
4.Mounted將編譯模板進(jìn)行數(shù)據(jù)注入,并將注入完成模板形成虛擬dom替換el指向原始dom

代碼:

var app = new Vue({
    el: "#app",
    data:{
        msg:"vue 生命周期",
        users:[], //定義一個(gè)users空數(shù)組,用來(lái)存貯所有用戶(hù)的信息
    },
    methods:{

    },
    computed:{

    },
    created(){ //執(zhí)行 data methods computed 等完成注入和校驗(yàn)
        //發(fā)送axios請(qǐng)求
        axios.get("http://localhost:8990/users").then(res=>{
            console.log(res.data);
            this.users = res.data;
        }); //es6 箭頭函數(shù) 注意:箭頭函數(shù)內(nèi)部沒(méi)有自己this  簡(jiǎn)化 function(){} //存在自己this
    },
});

2、測(cè)試

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-ERkeDKUK-1626677532969)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210716181201722.jpg)]

測(cè)試成功!??!

5、添加用戶(hù)信息

5.1、后端代碼編寫(xiě)

1、UserDAO接口層

//查詢(xún)所有用戶(hù)信息
List<User> findAll();

2、UserDAOMapper.xml

<!--save-->
<insert id="save" parameterType="User" useGeneratedKeys="true" keyProperty="id">
    insert into t_user values (#{id},#{name},#{salary},#{age},#{des})
</insert>

使用 mysql 自增長(zhǎng)序列,新插入一條數(shù)據(jù)時(shí),怎么得到主鍵?

加入以下屬性即可:

useGeneratedKeys=“true” keyProperty=“id”

useGeneratedKeys 取值范圍true、false 默認(rèn)值是:false。 含義:設(shè)置是否使用JDBC的getGenereatedKeys方法獲取主鍵并賦值到keyProperty設(shè)置的領(lǐng)域模型屬性中。

keyProperty 取id的key值,主要是在主鍵是自增的情況下,添加成功后可以直接使用主鍵值,其中keyProperty的值是對(duì)象的屬性值,不是數(shù)據(jù)庫(kù)表中的字段名。

3、service層編寫(xiě)

UserService類(lèi)

//保存用戶(hù)信息
void save(User user);

UserServiceImpl類(lèi)

@Override
public void save(User user) {
    userDAO.save(user);
}

4、UserController控制類(lèi)

//添加員工信息接口
@PostMapping("saveOrUpdate")
public void saveOrUpdate(@RequestBody User user){
    System.out.println(user);
    userService.save(user);
}

5.2、前端代碼編寫(xiě)

1、form表單中添加v-model雙向綁定

</div>
<div class="form-group">
    <label for="name">姓名</label>
    <input type="text" class="form-control" v-model="user.name" id="name" placeholder="請(qǐng)輸入姓名">
</div>
<div class="form-group">
    <label for="salary">工資</label>
    <input type="text" class="form-control" v-model="user.salary" id="salary" placeholder="請(qǐng)輸入工資">
</div>
<div class="form-group">
    <label for="age">年齡</label>
    <input type="text" class="form-control" v-model="user.age" id="age" placeholder="請(qǐng)輸入年齡">
</div>
<div class="form-group">
    <label for="description">個(gè)人簡(jiǎn)介</label>
    <input type="text" class="form-control" v-model="user.des" id="description" placeholder="請(qǐng)輸入個(gè)人簡(jiǎn)介">
</div>
<button type="button" class="btn btn-primary btn-block" @click="saveOrUpdate">提交</button>

2、給提交按鈕綁定 saveOrUpdate方法

    var app = new Vue({
        el: "#app",
        data:{
            msg:"vue 生命周期",
            users:[], //定義一個(gè)users空數(shù)組,用來(lái)存貯所有用戶(hù)的信息
            user:{},  //定義了一個(gè)空的json對(duì)象
        },
        methods:{
            saveOrUpdate(){ //保存或者修改方法
                //發(fā)送添加的請(qǐng)求
                console.log(this.user);
                axios.post("http://localhost:8990/saveOrUpdate",this.user).then(res=>{
                    this.user={}; //添加成功,清空數(shù)據(jù)
                    alert('用戶(hù)信息更新成功!');
                    //更新原始列表的數(shù)據(jù)
                    this.findAll(); //調(diào)用查詢(xún)所有
                }).catch(err=>{
                    alert('用戶(hù)信息更新失敗!')
                });
            },
            findAll(){
                //發(fā)送axios請(qǐng)求
                axios.get("http://localhost:8990/users").then(res=>{
                    console.log(res.data);
                    this.users = res.data;
                }); //es6 箭頭函數(shù) 注意:箭頭函數(shù)內(nèi)部沒(méi)有自己this  簡(jiǎn)化 function(){} //存在自己this
            }
        },

3、測(cè)試一下

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-XUAecTFJ-1626677532970)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210717111531326.jpg)]

測(cè)試成功!??!

6、修改用戶(hù)信息

6.1、后端代碼

1、UserDAO類(lèi)

//更新用戶(hù)信息
void update(User user);

//基于id查詢(xún)用戶(hù)信息
User findById(Integer id);

2、UserDAOMapper.xml

<!--update-->
<update id="update" parameterType="User">
    update t_user
    set
    name = #{name},
    age = #{age},
    salary = #{salary},
    des = #{des}
    where id = #{id}
</update>

<!--findById-->
<select id="findById" parameterType="Integer" resultType="User">
    select
    id,name,age,salary,des
    from t_user
    where id = #{id}
</select>

3、service

UserService類(lèi)

//修改用戶(hù)信息
void update(User user);

//基于id查詢(xún)用戶(hù)信息
User findById(Integer id);

UserServiceImpl實(shí)現(xiàn)類(lèi)

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

@Override
@Transactional(propagation = Propagation.SUPPORTS) //方法上聲明事務(wù)注解  Propagation:事務(wù)傳播屬性 支持事務(wù)
public User findById(Integer id) {
    return userDAO.findById(id);
}

4、control

在這里我們要根據(jù)前端請(qǐng)求的參數(shù)進(jìn)行判斷。如果前端請(qǐng)求的參數(shù)中id為空,說(shuō)明是添加操作,否則是更新操作,我們執(zhí)行相對(duì)應(yīng)的代碼。

//添加員工信息接口
@PostMapping("saveOrUpdate")
public void saveOrUpdate(@RequestBody User user){
    log.info("接收的業(yè)務(wù)邏輯:{}",user);
    //判斷是否存在id
    //存在: 更新操作      不存在id: 添加操作
    if(StringUtils.isEmpty(user.getId())){ //如果為空
        log.info("添加業(yè)務(wù)邏輯......");
        userService.save(user);  //添加
    }else{
        log.info("更新業(yè)務(wù)邏輯......");
        userService.update(user);
    }

}

6.2、前端代碼

我們點(diǎn)擊修改按鈕,顯示用戶(hù)信息。

1、我們先給修改按鈕添加根據(jù)id查詢(xún)用戶(hù)信息事件

<a href="" class=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btn btn-info btn-sm" @click.prevent="userEditDetail(user.id)">修改</a>

2、userEditDetail(id)

userEditDetail(id){  //用來(lái)在表單中將當(dāng)前點(diǎn)擊用戶(hù)信息進(jìn)行回顯
    axios.get("http://localhost:8990/user/"+id).then(res=>{
        this.user = res.data;  //完成數(shù)據(jù)回顯
    });
},

3、給提交按鈕綁定修改或者添加用戶(hù)信息事件

<button type="button" class="btn btn-primary btn-block" @click="saveOrUpdate">提交</button>

4、saveOrUpdate()

saveOrUpdate(){ //保存或者修改方法
    if(!this.user.name){
        alert("姓名不能為空!");
        return ;
    }
    console.log(this.user);
    axios.post("http://localhost:8990/saveOrUpdate",this.user).then(res=>{
        this.user={}; //添加成功,清空數(shù)據(jù)
        alert('用戶(hù)信息更新成功!');
        //更新原始列表的數(shù)據(jù)
        this.findAll(); //調(diào)用查詢(xún)所有
    }).catch(err=>{
        alert('用戶(hù)信息更新失敗!')
    });
},
},
findAll(){
    //發(fā)送axios請(qǐng)求
    axios.get("http://localhost:8990/users").then(res=>{
        console.log(res.data);
        this.users = res.data;
    }); //es6 箭頭函數(shù) 注意:箭頭函數(shù)內(nèi)部沒(méi)有自己this  簡(jiǎn)化 function(){} //存在自己this
},

5、測(cè)試一下

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-bsz7p8mt-1626677532970)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210717175122673.jpg)]

測(cè)試成功?。?!

7、刪除用戶(hù)信息

7.1、后端代碼

1、UserDAO接口

//基于id刪除用戶(hù)信息
void delete(Integer id);

2、UserDAOMapper.xml

<!--delete-->
<delete id="delete" parameterType="Integer">
    delete from t_user where id = #{id}
</delete>

3、service

UserService類(lèi)

//根據(jù)id刪除用戶(hù)信息
void delete(Integer id);

UserServiceImpl類(lèi)

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

4、controller類(lèi)

//根據(jù)id刪除用戶(hù)信息的接口
@DeleteMapping("delete/{id}")
public void delete(@PathVariable Integer id){
    userService.delete(id);
}

7.2、前端代碼

1、給刪除按鈕綁定刪除事件

<a href="javascript:;" rel="external nofollow"  class="btn btn-danger btn-sm" @click="delUser(user.id)">刪除</a>

2、delUser(id)刪除用戶(hù)方法

delUser(id){ //刪除用戶(hù)方法
    //友情提醒刪除
    if(window.confirm("您確定要?jiǎng)h除這條記錄嗎?")){
        axios.delete("http://localhost:8990/delete/"+id).then(res=>{
            alert("用戶(hù)信息刪除成功!");
            this.findAll(); 調(diào)用查詢(xún)所有
        }).catch(err=>{
            alert("用戶(hù)信息刪除失敗!");
        });
    }
}

3、測(cè)試一下

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來(lái)直接上傳(img-1SQbhCIt-1626677532972)(Vue用戶(hù)列表頁(yè)面開(kāi)發(fā).assets/image-20210717202211642.jpg)]

刪除信息成功?。?!

到此這篇關(guān)于Vue結(jié)合Springboot實(shí)現(xiàn)用戶(hù)列表單頁(yè)面(前后端分離)的文章就介紹到這了,更多相關(guān)Vue結(jié)合Springboot用戶(hù)列表內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決spring data jpa 批量保存更新的問(wèn)題

    解決spring data jpa 批量保存更新的問(wèn)題

    這篇文章主要介紹了解決spring data jpa 批量保存更新的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • Go Java算法之字符串中第一個(gè)唯一字符詳解

    Go Java算法之字符串中第一個(gè)唯一字符詳解

    這篇文章主要為大家介紹了Go Java算法之字符串中第一個(gè)唯一字符詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • javaweb 實(shí)現(xiàn)文件下載的方法及實(shí)例代碼

    javaweb 實(shí)現(xiàn)文件下載的方法及實(shí)例代碼

    這篇文章主要介紹了javaweb 實(shí)現(xiàn)文件下載的方法的相關(guān)資料,這里提供了實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2016-11-11
  • gson ajax 數(shù)字精度丟失問(wèn)題的解決方法

    gson ajax 數(shù)字精度丟失問(wèn)題的解決方法

    下面小編就為大家?guī)?lái)一篇gson ajax 數(shù)字精度丟失問(wèn)題的解決方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • springboot與mybatis整合實(shí)例詳解(完美融合)

    springboot與mybatis整合實(shí)例詳解(完美融合)

    大家都知道springboot搭建一個(gè)spring框架只需要秒秒鐘。下面通過(guò)實(shí)例代碼給大家介紹一下springboot與mybatis的完美融合,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-09-09
  • java實(shí)現(xiàn)單機(jī)版五子棋

    java實(shí)現(xiàn)單機(jī)版五子棋

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)單機(jī)版五子棋源碼,以及五子棋游戲需要的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Spring學(xué)習(xí)筆記1之IOC詳解盡量使用注解以及java代碼

    Spring學(xué)習(xí)筆記1之IOC詳解盡量使用注解以及java代碼

    這篇文章主要介紹了Spring學(xué)習(xí)筆記1之IOC詳解盡量使用注解以及java代碼 的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • spring boot使用properties定義短信模板的方法教程

    spring boot使用properties定義短信模板的方法教程

    這篇文章主要給大家介紹了關(guān)于spring boot使用properties定義短信模板的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • SpringBoot的@Conditional條件注解詳解

    SpringBoot的@Conditional條件注解詳解

    這篇文章主要介紹了SpringBoot的@Conditional條件注解詳解,打開(kāi)每個(gè)自動(dòng)配置類(lèi),都會(huì)看到@Conditional或其衍生的條件注解,本節(jié)我們來(lái)認(rèn)識(shí)下@Conditional注解,需要的朋友可以參考下
    2023-12-12
  • SpringBoot2 整合 ClickHouse數(shù)據(jù)庫(kù)案例解析

    SpringBoot2 整合 ClickHouse數(shù)據(jù)庫(kù)案例解析

    這篇文章主要介紹了SpringBoot2 整合 ClickHouse數(shù)據(jù)庫(kù)案例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10

最新評(píng)論

克什克腾旗| 盖州市| 平舆县| 泾源县| 沙河市| 龙岩市| 九寨沟县| 深泽县| 开江县| 梨树县| 沾化县| 北海市| 沐川县| 新营市| 咸宁市| 理塘县| 磐安县| 宝坻区| 张家口市| 汪清县| 嵩明县| 浦东新区| 孟津县| 安丘市| 台湾省| 成武县| 仁布县| 海门市| 资阳市| 浑源县| 芦溪县| 阿拉善盟| 兴隆县| 盈江县| 高平市| 湘乡市| 南通市| 南召县| 庄河市| 襄城县| 宜良县|