指定数据库表名
@TableName("tianshu_log_event")
//@IdClass(EventCompositePK.class) // 联合主键
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
public static final String TABLE_NAME = "tianshu_log_event";
指定主键字段
@TableId(value = "id", type = IdType.ASSIGN_ID) //生成id的类型:数据库自增(AUTO)、默认id生成器(ASSIGN_ID)、自定义id生成器(INPUT)
private Long id;
映射属性和表字段
@TableField(value = "content")
private String content;
不参与序列化,不会作为数据字段
private transient Integer eventId;
private static Integer eventId;
@TableField(exist = false)
private Integer eventId;
CRUD
条件构造器
com.baomidou.mybatisplus.core.conditions.AbstractWrapper
第3章 MyBatis-Plus查询方法
本章主要介绍MyBatis-Plus查询的主要内容,包括普通查询、条件构造器查询、select不列出全部字段查询等内容。
QueryWrapper
new QueryWrapper<Event>().orderBy(true, !isDesc, orderBy)
.like(Boolean.valueOf(nameLike), searchName, searchValue);
只列出id和owner字段
wrapper.select("id", "owner").likeLeft("owner", "sp").gt("level", 3);
不列出owner和content字段(对主键:id不生效)
wrapper.likeLeft("owner", "sp").gt("level", 3)
.select(
Event.class
, info -> !info.getColumn().equals("owner") && !info.getColumn().equals("content"));
- 3-7 condition作用 (06:47)
- 3-8 实体作为条件构造器构造方法的参数 (06:24)
- 3-9 AllEq用法 (06:10)
- 3-10 其他使用条件构造器的方法 (10:36)
- 3-11 lambda条件构造器 (09:49)
第4章 自定义sql及分页查询
本章介绍MyBatis-Plus中自定义sql和分页查询的内容。
第5章 更新及删除
介绍MyBatis-Plus中更新和删除功能的使用。
第6章 AR模式、主键策略和基本配置
本章介绍MyBatis-Plus中的AR模式、主键策略和基本配置等内容。
@Mapper
public interface EventMapper extends BaseMapper<Event> {
...
}
public class Event extends Model<Event> implements Serializable {
private static final long serialVersionUID = 1L;
...
}
@Autowired
private Event event;
@GetMapping(path = "/ActiveRecord/{id}/")
pub