SpringBoot(47) — MyBatis-plus删除数

2021-11-22  本文已影响0人  奔跑的佩恩

前言

在之前的文章已经讲过了MyBatis-plus的更新数据,大家有兴趣的话可参看以下文章
SpringBoot(40) — SpringBoot整合MyBatis-plus
SpringBoot(41) — MyBatis-plus常用查询
SpringBoot(42) — MyBatis-plus查询数据表中一列数据的部分字段
SpringBoot(43) — MyBatis-plus一些特殊查询
SpringBoot(44) — MyBatis-plus自定义sql查询
SpringBoot(45) — MyBatis-plus分页查询
SpringBoot(46) — MyBatis-plus更新数据
今天就让我们来讲讲MyBatis-plus的删除数据功能吧。
今天涉及知识:

  1. 前期配置
  2. 删除功能
    2.1 根据id删除
    2.2 map删除
    2.3 根据id 批量删除
    2.4 条件构造器Wrapper删除

一. 前期配置

先要在SpringBoot项目中配置好MyBatis-plus,准备一个数据库(我这里采用的MySql数据库),连接上并开启数据库服务。
准备一个数据表映射实体类Student,然后是继承BaseMapper实现的数据表操作类StudentMapper
先给出数据库test_prodemo表的数据:

image.png
接着给出Student类代码:
/**
 * Title:
 * description:
 * autor:pei
 * created on 2019/9/3
 */
@Data
@Component("Student")
@TableName(value = "demo")
public class Student {

    //主键自增
    @TableId(value = "id",type = IdType.AUTO)
    private int id;

    @TableField(value = "name") //表属性
    private String name;

    @TableField(value = "age") //表属性
    private int age;

}

最后给出数据表操作类StudentMapper代码:

/**
 * Title:
 * description:
 * autor:pei
 * created on 2019/9/3
 */
@Repository
public interface StudentMapper extends BaseMapper<Student> {

}

我用的MyBatis-plus版本为:

        <!-- mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.3.4</version>
        </dependency>

这样,前期准备工作就做好了。

二. 删除功能

2.1 根据id删除
上一篇下一篇

猜你喜欢

热点阅读