mybatis plus實體類註解使用

2021-10-07 20:46:27 字數 2002 閱讀 9928

mybatis-plus(簡稱 mp)是乙個 mybatis 的增強工具,在 mybatis 的基礎上只做增強不做改變,為簡化開發、提高效率而生。

@tableid(value = 「id」, type = idtype.auto):自增

@tableid(value = 「id」, type = idtype.id_worker_str):分布式全域性唯一id字串型別

@tableid(value = 「id」, type = idtype.input):自行輸入

@tableid(value = 「id」, type = idtype.id_worker):分布式全域性唯一id 長整型型別

@tableid(value = 「id」, type = idtype.uuid):32位uuid字串

@tableid(value = 「id」, type = idtype.none):無狀態

@tablename

(value =

"em_t"

)public

class

test

@tablefield(value = 「age」)// 用來解決資料庫中的字段和實體類的字段不匹配問題

@tablefield(exist = false) // 用來解決實體類中有的屬性但是資料表中沒有的字段,預設為true

@tablefield(condition = sqlcondition.like):表示該屬性可以模糊搜尋。

@tablefield(fill = fieldfill.insert):註解填充字段 ,生成器策略部分也可以配置! 值

描述value

字段值(駝峰命名方式,該值可無)

update

預處理 set 字段自定義注入

condition

預處理 where 實體條件自定義運算規則

el詳看注釋說明

exist

是否為資料庫表字段( 預設 true 存在,false 不存在 )

strategy

字段驗證 (預設 非 null 判斷,檢視 com.baomidou.mybatisplus.enums.fieldstrategy )

fill

字段填充標記 ( fieldfill, 配合自動填充使用 )值描述

default

預設不處理

insert

插入填充字段

update

更新填充字段

insert_update

插入和更新填充字段

@tablefield

(value =

"ename"

)private string ename;

@tablefield(.

., update=

"%s+1"

) 其中 %s 會填充為字段

輸出 sql 為:update 表 set 字段=欄位+

1 where ...

@tablefield(.

., update=

"now()"

) 使用資料庫時間

輸出 sql 為:update 表 set 字段=

now(

) where ...

@tablefield

(condition = sqlcondition.like)

private string name;

輸出 sql 為:select 表 where name like concat

('%'

,值,'%'

)

spring boot JPA中實體類常用註解

spring boot jpa中的註解很多,引數也比較多。沒必要全部記住,但是經常檢視官方文件也比較麻煩,記錄一下一些常用的註解。通過一些具體的例子來幫助記憶。entity table name flow sqldelete sql update flow set deleted 1 where i...

MyBatisPlus實現實體類注入列舉型別字段

為了加強實體類中,特殊字段型別的可讀性和省去資料型別的轉換,我們今天嘗試把int型別,例如狀態這種整型欄位換做列舉,下面是舊 data equalsandhashcode callsuper false accessors chain true tablename gdt targeting api...

建立實體類

下面直奔今天的主題 建立實體類 一點小插曲 接觸abp框架之前,一直都是使用的ef的dbfirst,在那種模式下,我們只要設計好資料庫,然後直接通過模板就生成了實體層,甚至都沒怎麼留意實體層的 是什麼樣子。現在要使用codefirst,就要反過來,先要寫 了,真有點不適應。好吧,為了學好abp,也要...