SpringBoot
  • Introduction
  • springboot日志
    • logstash-json日志
  • springboot数据库
    • 初始化数据库
  • MongoDB使用
    • SpringBoot整合MongoDB(1)
    • SpringBoot整合MongoDB(2)
    • SpringBoot整合MongoDB(3)
    • SpringBoot整合MongoDB(4)
  • prometheus监控
    • springboot整合prometheus(一)
    • springboot整合prometheus(二)
    • springboot整合prometheus(三)
    • springboot整合prometheus(四)
    • springboot整合prometheus(五)
  • spring IOC
    • 注解IOC
  • 过滤器和拦截器
    • 过滤器
    • 拦截器
  • mybatis
    • springboot快速整合mybatis
  • 使用缓存
    • redis-cache
  • 异步线程池
    • 快速开始
    • 线程池
  • AOP切面
    • 快速开始
  • 限流
    • 使用Sentinel实现接口限流
      • 使用Sentinel实现接口限流
  • MybatisPlus
    • 快速开始
    • 基本使用
    • 查询方法
    • 主键策略和基本配置
Powered by GitBook
On this page
  • 1. 特性1 - 自动生成id
  • 特性2 - 下划线和驼峰自动转换
  • 特性3 - 常用注解
  • 特性4 - 排除非表字段的三种方式
  • 4.1 关键字 transient 标示的字段不参与序列化过程
  • 4.2 关键字 static 标示的字段
  • 4.3 @TableField(exist = false)

Was this helpful?

  1. MybatisPlus

基本使用

1. 特性1 - 自动生成id

先定义一个普通的po

@Data
public class User {

    private Long id;

    private String name;

    private Integer age;

    private String email;
}

我们在保存对象的时候,并没有设置id主键

User user = new User();

user.setAge(23);
user.setEmail("2332fw@qq.com");
user.setName("woms");
userMapper.insert(user);

mybatis-plus会自动帮我们生成id

DEBUG==>  Preparing: INSERT INTO user ( id, name, age, email ) VALUES ( ?, ?, ?, ? ) 
DEBUG==> Parameters: 1135178229880168450(Long), woms(String), 23(Integer), 2332fw@qq.com(String)
DEBUG<==    Updates: 1

特性2 - 下划线和驼峰自动转换

特性3 - 常用注解

主键、字段和表名的显式声明

@Data
@TableName("user")
public class User {

    @TableId("id")
    private Long id;

    private String name;


    private Integer age;

    @TableField("email")
    private String email;
}

特性4 - 排除非表字段的三种方式

4.1 关键字 transient 标示的字段不参与序列化过程

private transient String remark;

4.2 关键字 static 标示的字段

由于static字段属于类不属于对象,全局就一个,不符合我们的正常使用

4.3 @TableField(exist = false)

@TableField(exist = false)
private String remark;
Previous快速开始Next查询方法

Last updated 5 years ago

Was this helpful?