MyBatis-Plus @TableField详解

@TableField

属性类型描述
valueString数据库字段名
existbooleanexist = false 表示该属性不是数据库字段,新增等使用bean的时候,mybatis-plus就会忽略这个,不会报错
conditionString预处理 where 实体查询比较条件,有值设置则按设置的值为准,没有则为默认全局的 %s=#{%s}@TableField(condition = SqlCondition.LIKE)输出SQL为: select 表 where name LIEK CONCAT('%',值,'%')
updateString预处理 update set 部分注入,例如:当在age字段上注解update=“%s+1” 表示更新时会 set age=age+1 (该属性优先级高于 el 属性)
insertStrategyFieldStrategyMybatis-plus insert对字段的操作
updateStrategyFieldStrategyMybatis-plus update对字段的操作
whereStrategyFieldStrategyMybatis-plus where条件对字段的操作
fillFieldFill字段自动填充策略
selectboolean@TableField(select = false) 查询时,则不返回该字段的值 。
keepGlobalFormatboolean是否保持使用全局的 format 进行处理
jdbcTypeJdbcTypeJDBC 类型 (该默认值不代表会按照该值生效)
typeHandlerClass<? extends TypeHandler>类型处理器 (该默认值不代表会按照该值生效)
numericScaleString指定小数点后保留的位数

FieldStrategy

描述
IGNORED忽略判断,该字段值不论是什么,都进行更新
NOT_NULL(默认)不为null则更新,字段值为null则不更新该字段
NOT_EMPTY不为空则更新,注意该字段值为null或为""(空字符串)都不会更新
DEFAULT默追随全局配置,和IGNORED 中的配置保持一致
NEVER不做更新操作,该字段值不论是什么,都不进行更新

FieldFill

描述
DEFAULT默认不处理
INSERT插入时填充字段
UPDATE更新时填充字段
INSERT_UPDATE插入和更新时填充字段

相关例子

例子描述
@TableField(select = false)不返回字段的值,但单独查询该字段就可以返回值,freezerDevice.selectList(Wrappers.<FreezerDevice>lambdaQuery().select(FreezerDevice::getChannel))
@TableField(insertStrategy = FieldStrategy.IGNORED)Mybatis-plus insert 会忽略该字段值的判断
@TableField(updateStrategy = FieldStrategy.IGNORED)Mybatis-plus update 会忽略该字段值的判断
@TableField(whereStrategy = FieldStrategy.IGNORED)Mybatis-plus where条件中会忽略该字段值的判断
@TableField(insertStrategy = FieldStrategy.IGNORED,updateStrategy = FieldStrategy.IGNORED,whereStrategy = FieldStrategy.IGNORED)insertStrategy 、updateStrategywhereStrategy 可以聚合操作
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值