← 返回首页
MybatisPlus基础教程(十五)
发表时间:2020-12-16 22:24:51
@TableName和@TableField

1.@TableName

通常用于实体类和表名不一致的情况,例如:

@TableName(value="tb_employee")
public class Employee{

}

2.@TableField 通常实现字段的自动注入和属性是否持久化。

字段自动注入。

@TableField(fill = FieldFill.INSERT_UPDATE)
@Column(length = 32)
protected String modifyTime;

属性是否持久化,类似于JPA的@Transient

@Transient //jpa的语法规则,表示validateCode不会映射为表字段
@TableField(exist = false) //mybatis plus语法,表示validateCode不会映射为表字段
private String validateCode;

预处理 set 字段自定义注入。


@TableField(update="%s+1") //其中 %s 会填充为字段
private int counter;