【学习日记2023.6.7】之 MyBatisPlus入门

news2024/10/7 6:49:11

文章目录

  • MybatisPlus
    • 1. 入门案例
      • 1.1 SpringBoot整合MyBatisPlus入门程序
    • 2. MyBatisPlus概述
      • 2.1 MyBatis介绍
      • 2.2 MyBatisPlus特性
    • 3. MyBatisPlus的CRUD操作
    • 4. MyBatisPlus分页功能
    • 5. 开启MyBatisPlus日志
      • 5.1 解决日志打印过多问题
        • 5.1.1 取消初始化spring日志打印
        • 5.1.2 取消SpringBoot启动banner图标
        • 5.1.3 取消MybatisPlus启动banner图标
    • 6. DQL编程控制
      • 6.1 条件查询方式
        • 6.1.1 条件查询
          • 方式一:按条件查询
          • 方式二:lambda格式按条件查询
          • 方式三:lambda格式按条件查询(推荐)
        • 6.1.2 组合条件
          • 并且关系(and)
          • 或者关系(or)
        • 6.1.3 NULL值处理
          • 问题导入
          • if语句控制条件追加
          • 条件参数控制
          • 条件参数控制(链式编程)
      • 6.2 查询投影-设置【查询字段、分组、分页】
        • 6.2.1 查询结果包含模型类中部分属性
        • 6.2.2 查询结果包含模型类中未定义的属性
      • 6.3 查询条件设定
        • 6.3.1 查询条件
        • 6.3.2 查询API
      • 6.4 字段映射与表名映射
        • 6.4.1 问题一:表字段与编码属性设计不同步
        • 6.4.2 问题二:编码中添加了数据库中未定义的属性
        • 6.4.3 问题三:采用默认查询开放了更多的字段查看权限
        • 6.4.4 问题四:表名与编码开发设计不同步
    • 7. DML编程控制
      • 7.1 id生成策略控制(Insert)
        • 7.1.1 id生成策略控制(@TableId注解)
        • 7.1.2 全局策略配置
      • 7.2 多记录操作(批量Delete/Select)
        • 7.2.1 按照主键删除多条记录
        • 7.2.2 根据主键查询多条记录
      • 7.3 逻辑删除(Delete/Update)
        • 7.3.1 逻辑删除案例
      • 7.4 乐观锁(Update)
        • 7.4.1 乐观锁案例
    • 8. 快速开发-代码生成器
      • 8.1 MyBatisPlus提供模板
      • 8.2 工程搭建和基本代码编写
      • 8.3 开发者自定义配置

MybatisPlus

1. 入门案例

1.1 SpringBoot整合MyBatisPlus入门程序

①:创建新模块,选择Spring初始化,并配置模块相关基础信息
请添加图片描述

②:选择当前模块需要使用的技术集(仅保留JDBC)
请添加图片描述

③:手动添加MyBatisPlus起步依赖

<dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-boot-starter</artifactId>
 <version>3.4.1</version>
</dependency>
<dependency>
 <groupId>com.alibaba</groupId>
 <artifactId>druid</artifactId>
 <version>1.1.16</version>
</dependency>
<dependency>
 <groupId>org.projectlombok</groupId>
 <artifactId>lombok</artifactId>
 <version>1.18.26</version>
</dependency>
  • 注意事项1:由于mp并未被收录到idea的系统内置配置,无法直接选择加入
  • 注意事项2:如果使用Druid数据源,需要导入对应坐标

④:制作实体类与表结构(类名与表名对应,属性名与字段名对应)

create database if not exists mybatisplus_db character set utf8;
use mybatisplus_db;
CREATE TABLE user (
            id bigint(20) primary key auto_increment,
            name varchar(32) not null,
            password  varchar(32) not null,
            age int(3) not null ,
            tel varchar(32) not null
);
insert into user values(null,'tom','123456',12,'12345678910');
insert into user values(null,'jack','123456',8,'12345678910');
insert into user values(null,'jerry','123456',15,'12345678910');
insert into user values(null,'tom','123456',9,'12345678910');
insert into user values(null,'snake','123456',28,'12345678910');
insert into user values(null,'张益达','123456',22,'12345678910');
insert into user values(null,'张大炮','123456',16,'12345678910');
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private Long id;
    private String name;
    private String password;
    private Integer age;
    private String tel;
}

⑤:设置Jdbc参数(application.yml

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource #指定数据源类型为druid,springboot默认为hikari数据源
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC
    username: root
    password: root

⑥:定义数据接口,继承BaseMapper

package com.yishooo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yishooo.pojo.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

⑦:测试类中注入dao接口,测试功能

package com.yishooo.dao;

import com.yishooo.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class UserMapperTest {
    @Autowired
    private UserMapper userMapper;

    @Test
    void testGetAll() {
        List<User> userList = userMapper.selectList(null);
        System.out.println(userList);
    }
}

2. MyBatisPlus概述

2.1 MyBatis介绍

  • MyBatisPlus(简称MP)是基于MyBatis框架基础上开发的增强型工具,旨在简化开发、提高效率

  • 官网:https😕/mybatis.plus/ https://mp.baomidou.com/

2.2 MyBatisPlus特性

  • 无侵入:只做增强不做改变,不会对现有工程产生影响
  • 强大的 CRUD 操作:内置通用 Mapper,少量配置即可实现单表CRUD 操作
  • 支持 Lambda:编写查询条件无需担心字段写错
  • 支持主键自动生成
  • 内置分页插件
  • ……

3. MyBatisPlus的CRUD操作

请添加图片描述

package com.yishooo.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yishooo.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;


@SpringBootTest
public class CRUDTest {
 @Autowired
 private UserMapper userMapper;

 @Test
 public void testSave() throws Exception{
     User user = new User();
     user.setName("隔壁老王");
     user.setPassword("laowang");
     user.setAge(12);
     user.setTel("4008208820");
     userMapper.insert(user);
 }

 @Test
 void testDelete() {
     userMapper.deleteById(1666284193435480066L);
 }

 @Test
 void testUpdate() {
     User user = new User();
     user.setId(1L);
     user.setName("Tom888");
     user.setPassword("tom888");
     userMapper.updateById(user);
 }

 @Test
 void testGetById() {
     User user = userMapper.selectById(2L);
     System.out.println(user);
 }


 @Test
 void testGetAll() {
     List<User> userList = userMapper.selectList(null);
     for (User user : userList) {
         System.out.println(user);
     }
 }
}

4. MyBatisPlus分页功能

分页功能接口
请添加图片描述

MyBatisPlus分页使用

①:设置分页拦截器作为Spring管理的bean

package com.yishooo.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MPConfig {
 @Bean
 public MybatisPlusInterceptor mybatisPlusInterceptor(){
     //1 创建MybatisPlusInterceptor拦截器对象
     MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
     //2 添加分页拦截器
     interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
     return interceptor;
 }
}

②:执行分页查询

//分页查询
@Test
void testSelectPage(){
 //1 创建IPage分页对象,设置分页参数
 IPage<User> page=new Page<>(1,3);
 //2 执行分页查询
 userDao.selectPage(page,null);
 //3 获取分页结果
 System.out.println("当前页码值:"+page.getCurrent());
 System.out.println("每页显示数:"+page.getSize());
 System.out.println("总页数:"+page.getPages());
 System.out.println("总条数:"+page.getTotal());
 System.out.println("当前页数据:"+page.getRecords());
}

5. 开启MyBatisPlus日志

spring:
datasource:
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.cj.jdbc.Driver
 url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC
 username: root
 password: root
# 开启mp的日志(输出到控制台)
mybatis-plus:
configuration:
 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

5.1 解决日志打印过多问题

5.1.1 取消初始化spring日志打印

请添加图片描述

在resources下新建一个logback.xml文件,名称固定,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

</configuration>

关于logback参考博客:https://www.jianshu.com/p/75f9d11ae011

5.1.2 取消SpringBoot启动banner图标

请添加图片描述

spring:
  main:
    banner-mode: off # 关闭SpringBoot启动图标(banner)

5.1.3 取消MybatisPlus启动banner图标

请添加图片描述

# mybatis-plus日志控制台输出
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    banner: off # 关闭mybatisplus启动图标

6. DQL编程控制

6.1 条件查询方式

  • MyBatisPlus将书写复杂的SQL查询条件进行了封装,使用编程的形式完成查询条件的组合
    请添加图片描述

6.1.1 条件查询

方式一:按条件查询
//方式一:按条件查询
QueryWrapper<User> qw=new QueryWrapper<>();
qw.lt("age", 18);
List<User> userList = userMapper.selectList(qw);
System.out.println(userList);
方式二:lambda格式按条件查询
//方式二:lambda格式按条件查询
QueryWrapper<User> qw = new QueryWrapper<User>();
qw.lambda().lt(User::getAge, 10);
List<User> userList = userMapper.selectList(qw);
System.out.println(userList);
方式三:lambda格式按条件查询(推荐)
//方式三:lambda格式按条件查询
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
lqw.lt(User::getAge, 10);
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);

6.1.2 组合条件

并且关系(and)
//并且关系
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//并且关系:10到30岁之间
lqw.lt(User::getAge, 30).gt(User::getAge, 10);
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);
或者关系(or)
//或者关系
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//或者关系:小于10岁或者大于30岁
lqw.lt(User::getAge, 10).or().gt(User::getAge, 30);
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);

6.1.3 NULL值处理

问题导入

如下搜索场景,在多条件查询中,有条件的值为空应该怎么解决?
请添加图片描述

if语句控制条件追加
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
if(minAge!=null){
    lqw.gt(User::getAge, minAge);
}
if(maxAge!=null){
    lqw.lt(User::getAge, maxAge);
}
List<User> userList = userMapper.selectList(lqw);
userList.forEach(System.out::println);
条件参数控制
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//参数1:如果表达式为true,那么查询才使用该条件
lqw.gt(minAge!=null,User::getAge, minAge);
lqw.lt(maxAge!=null,User::getAge, maxAge);
List<User> userList = userMapper.selectList(lqw);
userList.forEach(System.out::println);
条件参数控制(链式编程)
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//参数1:如果表达式为true,那么查询才使用该条件
lqw.gt(minAge!=null,User::getAge, minAge)
   .lt(maxAge!=null,User::getAge, maxAge);
List<User> userList = userMapper.selectList(lqw);
userList.forEach(System.out::println);

6.2 查询投影-设置【查询字段、分组、分页】

6.2.1 查询结果包含模型类中部分属性

/*LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
lqw.select(User::getId, User::getName, User::getAge);*/
//或者
QueryWrapper<User> lqw = new QueryWrapper<User>();
lqw.select("id", "name", "age", "tel");
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);

6.2.2 查询结果包含模型类中未定义的属性

QueryWrapper<User> lqw = new QueryWrapper<User>();
lqw.select("count(*) as count, tel");
lqw.groupBy("tel");
List<Map<String, Object>> userList = userMapper.selectMaps(lqw);
System.out.println(userList);

6.3 查询条件设定

多条件查询有哪些组合?

  • 范围匹配(> 、 = 、between)
  • 模糊匹配(like)
  • 空判定(null)
  • 包含性匹配(in)
  • 分组(group)
  • 排序(order)
  • ……

6.3.1 查询条件

  • 用户登录(eq匹配)
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//等同于=
lqw.eq(User::getName, "Jerry").eq(User::getPassword, "jerry");
User loginUser = userMapper.selectOne(lqw);
System.out.println(loginUser);
  • 购物设定价格区间、户籍设定年龄区间(le ge匹配 或 between匹配)
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//范围查询 lt le gt ge eq between
lqw.between(User::getAge, 10, 30);
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);
  • 查信息,搜索新闻(非全文检索版:like匹配)
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();
//模糊匹配 like %J% 不走索引 效率较低
lqw.likeRight(User::getName, "J");//J% 走索引
List<User> userList = userMapper.selectList(lqw);
System.out.println(userList);
  • 统计报表(分组查询聚合函数)
QueryWrapper<User> qw = new QueryWrapper<User>();
qw.select("age","count(*) as nums");
qw.groupBy("age");
List<Map<String, Object>> maps = userMapper.selectMaps(qw);
System.out.println(maps);

6.3.2 查询API

  • 更多查询条件设置参看 https://mybatis.plus/guide/wrapper.html#abstractwrapper

6.4 字段映射与表名映射

思考表的字段和实体类的属性不对应,查询会怎么样?

6.4.1 问题一:表字段与编码属性设计不同步

  • 在模型类属性上方,使用**@TableField**属性注解,通过==value==属性,设置当前属性对应的数据库表中的字段关系。
    请添加图片描述

6.4.2 问题二:编码中添加了数据库中未定义的属性

  • 在模型类属性上方,使用**@TableField注解,通过exist**属性,设置属性在数据库表字段中是否存在,默认为true。此属性无法与value合并使用。
    请添加图片描述

6.4.3 问题三:采用默认查询开放了更多的字段查看权限

  • 在模型类属性上方,使用**@TableField注解,通过select**属性:设置该属性是否参与查询。此属性与select()映射配置不冲突。
    请添加图片描述

6.4.4 问题四:表名与编码开发设计不同步

  • 模型类上方,使用**@TableName注解,通过value**属性,设置当前类对应的数据库表名称。
    请添加图片描述
@Data
@TableName("tbl_user")
public class User {
    /*
        id为Long类型,因为数据库中id为bigint类型,
        并且mybatis有自己的一套id生成方案,生成出来的id必须是Long类型
     */
    private Long id;
    private String name;
    @TableField(value = "pwd",select = false)
    private String password;
    private Integer age;
    private String tel;
    @TableField(exist = false) //表示online字段不参与CRUD操作
    private Boolean online;
}

7. DML编程控制

7.1 id生成策略控制(Insert)

主键生成的策略有哪几种方式?不同的表应用不同的id生成策略

  • 日志:自增(1,2,3,4,……)
  • 购物订单:特殊规则(FQ23948AK3843)
  • 外卖单:关联地区日期等信息(10 04 20200314 34 91)
  • 关系表:可省略id
  • ……

7.1.1 id生成策略控制(@TableId注解)

  • 名称:@TableId

  • 类型:属性注解

  • 位置:模型类中用于表示主键的属性定义上方

  • 作用:设置当前类中主键属性的生成策略

  • 相关属性

    type:设置主键属性的生成策略,值参照IdType枚举值(id有置值,默认赋置值)
    请添加图片描述

7.1.2 全局策略配置

mybatis-plus:
  global-config:
    db-config:
      id-type: assign_id #配置全局的id生成为雪花算法
      table-prefix: tb_ #配置表的统一的前缀

id生成策略全局配置
请添加图片描述

表名前缀全局配置
请添加图片描述

7.2 多记录操作(批量Delete/Select)

MyBatisPlus是否支持批量操作?

7.2.1 按照主键删除多条记录

//删除指定多条数据
List<Long> list = new ArrayList<>();
list.add(1402551342481838081L);
list.add(1402553134049501186L);
list.add(1402553619611430913L);

userMapper.deleteBatchIds(list);

7.2.2 根据主键查询多条记录

//查询指定多条数据
List<Long> list = new ArrayList<>();
list.add(1L);
list.add(3L);
list.add(4L);
userMapper.selectBatchIds(list);

7.3 逻辑删除(Delete/Update)

在实际环境中,如果想删除一条数据,是否会真的从数据库中删除该条数据?

  • 删除操作业务问题:业务数据从数据库中丢弃
  • 逻辑删除:为数据设置是否可用状态字段,删除时设置状态字段为不可用状态,数据保留在数据库中
    请添加图片描述

7.3.1 逻辑删除案例

①:数据库表中添加逻辑删除标记字段
请添加图片描述

②:实体类中添加对应字段,并设定当前字段为逻辑删除标记字段

package com.yishooo.pojo;

import com.baomidou.mybatisplus.annotation.*;

import lombok.Data;

@Data
public class User {

    private Long id;
    
    //逻辑删除字段,标记当前记录是否被删除
    @TableLogic
    private Integer deleted;
    
}

③:配置逻辑删除字面值

mybatis-plus:
  global-config:
    db-config:
      table-prefix: tbl_
      # 逻辑删除字段名
      logic-delete-field: deleted
      # 逻辑删除字面值:未删除为0
      logic-not-delete-value: 0
      # 逻辑删除字面值:删除为1
      logic-delete-value: 1

逻辑删除本质:逻辑删除的本质其实是修改操作。如果加了逻辑删除字段,查询数据时也会自动带上逻辑删除字段。
请添加图片描述

7.4 乐观锁(Update)

乐观锁主张的思想是什么?

  • 业务并发现象带来的问题:秒杀

7.4.1 乐观锁案例

①:数据库表中添加锁标记字段
请添加图片描述

②:实体类中添加对应字段,并设定当前字段为逻辑删除标记字段

package com.yishooo.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import lombok.Data;

@Data
public class User {

	private Long id;
	
    @Version
    private Integer version;
}

③:配置乐观锁拦截器实现锁机制对应的动态SQL语句拼装

package com.yishooo.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MpConfig {
    @Bean
    public MybatisPlusInterceptor mpInterceptor() {
        //1.定义Mp拦截器
        MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();

        //2.添加乐观锁拦截器
        mpInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        
        return mpInterceptor;
    }
}

④:使用乐观锁机制在修改前必须先获取到对应数据的verion方可正常进行

@Test
public void testUpdate() {
    /*User user = new User();
    user.setId(3L);
    user.setName("Jock666");
    user.setVersion(1);
    userMapper.updateById(user);*/
    
    //1.先通过要修改的数据id将当前数据查询出来
    //User user = userMapper.selectById(3L);
    //2.将要修改的属性逐一设置进去
    //user.setName("Jock888");
    //userMapper.updateById(user);
    
    //1.先通过要修改的数据id将当前数据查询出来
    User user = userMapper.selectById(3L);     //version=3
    User user2 = userMapper.selectById(3L);    //version=3
    user2.setName("Jock aaa");
    userMapper.updateById(user2);              //version=>4
    user.setName("Jock bbb");
    userMapper.updateById(user);               //verion=3?条件还成立吗?
}

8. 快速开发-代码生成器

如果只给一张表的字段信息,能够推演出Domain、Dao层的代码?

8.1 MyBatisPlus提供模板

  • Mapper接口模板
  • 实体对象类模板

8.2 工程搭建和基本代码编写

  • 第一步:创建SpringBoot工程,添加代码生成器相关依赖,其他依赖自行添加
<!--代码生成器-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.4.1</version>
</dependency>

<!--velocity模板引擎-->
<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity-engine-core</artifactId>
    <version>2.3</version>
</dependency>
  • 第二步:编写代码生成器类
package com.yishooo;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;

public class Generator {
    public static void main(String[] args) {
        //1. 创建代码生成器对象,执行生成代码操作
        AutoGenerator autoGenerator = new AutoGenerator();

        //2. 数据源相关配置:读取数据库中的信息,根据数据库表结构生成代码
        DataSourceConfig dataSource = new DataSourceConfig();
        dataSource.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        autoGenerator.setDataSource(dataSource);

         //3. 执行生成操作
        autoGenerator.execute();
    }
}

8.3 开发者自定义配置

  • 设置全局配置
//设置全局配置
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setOutputDir(System.getProperty("user.dir")+"/mybatisplus_04_generator/src/main/java");    //设置代码生成位置
globalConfig.setOpen(false);    //设置生成完毕后是否打开生成代码所在的目录
globalConfig.setAuthor("yishooo");    //设置作者
globalConfig.setFileOverride(true);     //设置是否覆盖原始生成的文件
globalConfig.setMapperName("%sMapper");    //设置数据层接口名,%s为占位符,指代模块名称
globalConfig.setIdType(IdType.ASSIGN_ID);   //设置Id生成策略
autoGenerator.setGlobalConfig(globalConfig);
  • 设置包名相关配置
//设置包名相关配置
PackageConfig packageInfo = new PackageConfig();
packageInfo.setParent("com.yishooo");   //设置生成的包名,与代码所在位置不冲突,二者叠加组成完整路径
packageInfo.setEntity("pojo");    //设置实体类包名
packageInfo.setMapper("mapper");   //设置数据层包名
autoGenerator.setPackageInfo(packageInfo);
  • 策略设置
//策略设置
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setInclude("tb_user");  //设置当前参与生成的表名,参数为可变参数
strategyConfig.setTablePrefix("tb_");  //设置数据库表的前缀名称,模块名 = 数据库表名 - 前缀名  例如: User = tb_user - tb_
strategyConfig.setRestControllerStyle(true);    //设置是否启用Rest风格
strategyConfig.setVersionFieldName("version");  //设置乐观锁字段名
strategyConfig.setLogicDeleteFieldName("deleted");  //设置逻辑删除字段名
strategyConfig.setEntityLombokModel(true);  //设置是否启用lombok
autoGenerator.setStrategy(strategyConfig);

说明:根据实际情况修改后可以直接使用。

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

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

相关文章

基于SpringBoot+Vue的学生考勤管理系统设计与实现

博主介绍&#xff1a; 大家好&#xff0c;我是一名在Java圈混迹十余年的程序员&#xff0c;精通Java编程语言&#xff0c;同时也熟练掌握微信小程序、Python和Android等技术&#xff0c;能够为大家提供全方位的技术支持和交流。 我擅长在JavaWeb、SSH、SSM、SpringBoot等框架下…

【Web服务器】基于Nginx搭建LNMP架构

文章目录 一、安装 MySQL 数据库1. 安装Mysql环境依赖包2. 创建运行用户3. 编译安装4. 修改mysql 配置文件5. 更改mysql安装目录和配置文件的属主属组6. 设置路径环境变量7. 初始化数据库8. 添加mysqld系统服务9. 修改mysql 的登录密码10. 授权远程登录 二、编译安装 nginx 服务…

2024」预备研究生mem-论据和结论为简单句(下)

一、论据和结论为简单句-建立联系 二、结论包含完成推理 改版&#xff1a; 三、课后题

盘点一个Python网络爬虫问题

点击上方“Python爬虫与数据挖掘”&#xff0c;进行关注 回复“书籍”即可获赠Python从入门到进阶共10本电子书 今 日 鸡 汤 在天愿作比翼鸟&#xff0c;在地愿为连理枝。 大家好&#xff0c;我是皮皮。 一、前言 前几天在Python最强王者群【刘桓鸣】问了一个Python网络爬虫的问…

8自由度并联腿机器狗实现行走功能

1. 功能说明 本文示例将实现R309a样机8自由度并联腿机器狗行走的功能。 2. 并联仿生机器人结构设计 机器狗是一种典型的并联仿生四足机器人&#xff0c;其腿部结构主要模仿了四足哺乳动物的腿部结构&#xff0c;主要由腿部的节段和旋转关节组成。在设计机器狗的腿部结构时&…

实用教学Prompt 提示词实战:如何用 ChatGPT 指导高考语文作文写作

又是一年高考季&#xff0c;牵动着广大学生和家长的心。7 日上午&#xff0c;语文科目考试结束。 今年高考语文共7套试卷&#xff1a;全国甲卷、全国乙卷、新课标Ⅰ卷、新课标Ⅱ卷、北京卷、天津卷、上海卷。 以高考语文作文题目来实践检验一下&#xff0c;如何用合适的提问词&…

chatgpt赋能python:Python将首字母变成大写——提升SEO排名的一种简单方法

Python将首字母变成大写——提升SEO排名的一种简单方法 在SEO行业中&#xff0c;优化关键字密度和网站结构是常规且必要的工作。但是&#xff0c;除此之外&#xff0c;我们也应该注意到一些看似微不足道但可能对网站排名产生影响的细节。比如&#xff0c;对于文章标题和正文的…

Mocha AE:Track 模块

当对跟踪踪结果不是很满意的时候&#xff0c;可尝试更改下 Track&#xff08;跟踪&#xff09;模块中的选项之后重新跟踪。 Input 输入 Clip 剪辑 选择要跟踪的素材。 --Input 输入 --Layer Below 下方图层 Track Individual Fields 跟踪单个场 针对隔行扫描素材&#xff0c;…

【IMX6ULL驱动开发学习】01.安装交叉编译环境【附下载地址】

第一步&#xff08;下载工具链&#xff09;&#xff1a; 从官网上下载交叉编译工具链 https://snapshots.linaro.org/gnu-toolchain/ 按照以下步骤选择 可以选择最新的&#xff08;我也忘记我用的哪个版本了&#xff0c;都可以用问题不大&#xff09; 第二步&#xff08;…

【Rust日报】2023-06-06 motus 一个非常方便的命令行密码生成工具

motus 一个非常简单的命令行密码生成工具 Motus是一个命令行应用&#xff0c;帮你轻松生成安全密码。 它的用户界面非常简单、优雅&#xff0c;跟 1Password 的密码生成器一样&#xff0c;让你感觉很舒服。Motus 默认会把生成的密码复制到你的剪贴板&#xff0c;用起来非常方便…

2023智源大会议程公开丨AI生命科学论坛

6月9日&#xff0c;2023北京智源大会&#xff0c;将邀请AI领域的探索者、实践者、以及关心智能科学的每个人&#xff0c;共同拉开未来舞台的帷幕&#xff0c;你准备好了吗&#xff1f;与会知名嘉宾包括&#xff0c;图灵奖得主Yann LeCun、OpenAI创始人Sam Altman、图灵奖得主Ge…

java设计模式之:策略模式

文章目录 什么是策略模式&#xff1f;策略模式结构策略模式适用场景简单示例项目实战场景用一坨坨代码实现策略模式重构代码代码实现优惠券接口优惠券接口实现策略控制类测试类 总结 设计模式是软件设计中常见问题的典型解决方案。 它们就像能根据需求进行调整的预制蓝图&#…

基于BP神经网络对MNIST数据集检测识别(Pytorch,Tensorflow版本)

基于BP神经网络对MNIST数据集检测识别 1&#xff0e;作者介绍2&#xff0e;基于BP神经网络对MNIST数据集检测识别2.1 BP神经网络介绍2.2 神经元模型2.3 激活函数2.4 BP神经网络基础架构2.5 BP神经网络正向传播反向传播 3&#xff0e;基于BP神经网络对MNIST数据集检测识别实验3.…

Playwright系列:第14章 Playwright性能测试实战

下方查看历史精选文章 重磅发布 - 自动化框架基础指南pdfv1.1大数据测试过程、策略及挑战 测试框架原理&#xff0c;构建成功的基石 在自动化测试工作之前&#xff0c;你应该知道的10条建议 在自动化测试中&#xff0c;重要的不是工具 功能测试可以验证应用程序的功能是否正常,…

Cocos Store打通企业提现,诚邀更多团队和公司入驻!

2023年5月29日 Cocos Store 终于上线&#xff0c;令众多开发者期盼已久的功能——企业对公提现。 在此&#xff0c;真诚地对大家说一声&#xff1a;抱歉&#xff0c;我们来晚了&#xff01; 但请一定相信 Cocos 引擎、Cocos Store 一直在努力并从未间断为开发者们创造价值&…

chatgpt赋能python:小黑框:Python程序员必备利器

小黑框&#xff1a;Python程序员必备利器 如果您是一名Python程序员&#xff0c;小黑框&#xff08;Terminal&#xff09;一定不陌生。小黑框是一种基于文本的用户界面&#xff0c;通常用于执行命令行任务&#xff0c;编写或调试代码等。Python程序员可以通过小黑框完成许多任…

【JUC基础】16. Fork Join

1、前言 “分而治之”一直是一个非常有效的处理大量数据的方法。著名的MapReduce也是采取了分而治之的思想。。简单地说&#xff0c;就是如果你要处理 1000 个数据&#xff0c;但是你并不具备处理 1000个数据的能力&#xff0c;那么你可以只处理其中的 10 个&#xff0c;然后分…

使用JSAPl来做一个倒计时的效果

今天的小案例需要做一个倒计时的效果 我们的时分秒需要一直进行倒计时&#xff0c;然后我们的页面颜色需要根据定时器的操作来进行更换&#xff0c;首先我们还是可以来分析一下我们的HTML步骤 <div class"countdown"><p class"next">今天是22…

HCIE-Cloud Computing LAB备考第二步:实战解题–第五题:论述二--跨数据中心部署问答--缩写法

跨数据中心部署 通常部署在同城或相近城市存在的两个数据中心&#xff0c;其物理距离在300km以内&#xff0c;两个数据中心均处于运行状态&#xff0c;可同时承担相同业务&#xff0c;提高数据中心的整体服务能力和系统资源利用率&#xff0c;当单数据中心故障时&#xff0c;业…

学会使用perf性能分析工具(含移植到arm-linux开发板)

文章目录 一、在ubuntu中使用apt包下载Perf二、使用源码安装Perf&#xff0c;并移植到arm-linux环境下三、使用perf四、Perf的功能介绍 系统&#xff1a;Ubuntu18.04系统 内核版本&#xff1a;5.4.0-150-generic&#xff08;通过uname -r查看&#xff09; 一、在ubuntu中使用ap…