mybatisplus 基本操作

2021-10-21 20:01:18 字數 982 閱讀 9520

mybatisplus日誌

mybatis-plus.configuration.log-impl=org.apach.ibatis.logging.stdout.stdoutimpl

設定mp的主鍵生成策略

在實體類的主鍵上加註解   @tableid(type=idtype.auto)

id_worker   mp自帶策略,生成19位值,數字型別使用這種策略,long

id_worker_str    字串型別

自動填充

@tablefield(fill = fieldfill.insert)

@tablefield(fill = fieldfill.insert_update)

編寫填充屬性類  implement metaobjecthandler

@override

public void insertfill(metaobject me)

mp樂觀鎖實現取出記錄時,獲取當前version 

更新時,帶上version

執行更新時,set version = new version where version = oldversion

如果version不對,更新失敗

mp簡單操作mp 邏輯刪除

1.欄位加註解  @tablelogic

2.配置外掛程式  @bean  isqlinjector return new logicsqlinjector()

3.加配置(可有可無)  mybatis-plus.global-config.db-config.logic-delete-

value=1   ...logic-not-delete..=0  

效能分析外掛程式

...

mybatis plus基本操作

只針對稍微有難度的,部分未涉及到的簡單操作可以參考官方文件 data equalsandhashcode callsuper false tablename user public class user implements serializable 1.插入物件,返回id user user ne...

MyBatis Plus基本操作總結

定義資料庫表 create table user id bigint 20 not null comment 主鍵id name varchar 30 null default null comment 姓名 age int 11 null default null comment 年齡 email...

mybatis plus的基本操作(CRUD)

runwith springjunit4classrunner.class contextconfiguration public class testmp02 tablename user 可以設定物件和表的對映 tableid type idtype.auto 可以設定id的主鍵自增 table...