MyBatis-Flex Agent快速開發技能

👤 star.qin 📦 v1.11.8 ⭐ 4.6 ⬇️ 445 下載
💻 開發程式設計 免費

📖 技能介紹


name: mybatis-flex-skills description: MyBatis-Flex框架開發專家技能。提供完整的MyBatis-Flex使用指導,包括Entity定義、QueryWrapper查詢構建、BaseMapper操作、多資料來源配置、多租戶、邏輯刪除、樂觀鎖、程式碼生成器等。 trigger_keywords: level_1: [MyBatis-Flex, mybatis-flex, MyBatis增強框架] level_2: [QueryWrapper, BaseMapper, Db+Row, UpdateChain, QueryChain] level_3: [邏輯刪除, 樂觀鎖, 多租戶, 多資料來源, @Table, @Column, @Id, APT配置] condition: level_2或level_3需要組合ORM/資料庫/實體類等關鍵詞

7w4.net收錄了海量優質技能外掛。


MyBatis-Flex 開發技能

MyBatis-Flex 是一個優雅的 MyBatis 增強框架,具有輕量、靈活、強大的特點。


文件索引

場景 文件 核心關鍵詞
Entity定義、註解配置 entity-annotations.md @Table, @Column, @Id, 監聽器
BaseMapper、Db+Row、鏈式操作 db-row-and-basemapper.md insert, update, delete, QueryChain
QueryWrapper高階用法 querywrapper-advanced.md select, where, join, 子查詢, CTE
關聯查詢 relations-query.md @RelationOneToOne, Join Query
Service層 service-layer.md save, remove, list, page
邏輯刪除、樂觀鎖、多資料來源、多租戶 advanced-features.md isLogicDelete, version, DataSourceKey
程式碼生成器、APT配置 codegen-and-apt.md Generator, processor
Kotlin開發、DSL查詢 kotlin-guide.md Kotlin, KSP, 中綴表示式
框架對比、SQL日誌、快取 other-features.md p6spy, 快取, 列舉

各模組詳細文件見 references/ 目錄


快速開始

<!-- 2.x: starter, 3.x: boot3-starter, 4.x: boot4-starter + jdbc -->
<dependency>
    <groupId>com.mybatis-flex</groupId>
    <artifactId>mybatis-flex-spring-boot-starter</artifactId>
    <version>1.11.7</version>
</dependency>
<dependency>
    <groupId>com.mybatis-flex</groupId>
    <artifactId>mybatis-flex-processor</artifactId>
    <version>1.11.7</version>
    <scope>provided</scope>
</dependency>
@SpringBootApplication
@MapperScan("com.your.package.mapper")
public class Application {}

詳見 codegen-and-apt.md


Entity 速查

@Table(value = "tb_account", dataSource = "ds2")
public class Account {
    @Id(keyType = KeyType.Auto)
    private Long id;
    @Column(value = "user_name")
    private String userName;
    @Column(isLogicDelete = true)
    private Boolean isDelete;
    @Column(version = true)
    private Integer version;
    @Column(tenantId = true)
    private Long tenantId;
    @ColumnMask(Masks.MOBILE_PHONE)
    private String phone;
}

詳見 entity-annotations.md


QueryWrapper 查詢

import static com.your.package.entity.table.AccountTableDef.ACCOUNT;

QueryWrapper query = QueryWrapper.create()
    .select(ACCOUNT.ID, ACCOUNT.USER_NAME)
    .from(ACCOUNT)
    .where(ACCOUNT.AGE.ge(18))
    .and(ACCOUNT.USER_NAME.like("張"))
    .orderBy(ACCOUNT.ID.desc());

// 動態條件
query.where(ACCOUNT.AGE.ge(18).when(age != null))
    .and(ACCOUNT.USER_NAME.like(name, If::hasText));

詳見 querywrapper-advanced.md


BaseMapper CRUD

public interface AccountMapper extends BaseMapper<Account> {}

accountMapper.insert(account);
accountMapper.selectOneById(1L);
accountMapper.selectListByQuery(query);
accountMapper.paginate(1, 10, query);
accountMapper.deleteById(1L);

// 部分欄位更新
Account entity = UpdateEntity.of(Account.class, 100L);
entity.setAge(20);
accountMapper.update(entity);

詳見 db-row-and-basemapper.md


關聯查詢

@RelationOneToOne(selfField = "id", targetField = "accountId")
private IDCard idCard;

@RelationOneToMany(selfField = "id", targetField = "accountId")
private List<Book> books;

@RelationManyToMany(joinTable = "tb_role_mapping",
    joinSelfColumn = "account_id", joinTargetColumn = "role_id")
private List<Role> roles;

詳見 relations-query.md


Service 層

public interface IAccountService extends IService<Account> {}

@Component
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account>
        implements IAccountService {}

accountService.save(account);
accountService.removeById(1L);
accountService.list(ACCOUNT.AGE.ge(18));
accountService.page(new Page<>(1, 10), query);

詳見 service-layer.md


高階特性

特性 註解/配置 說明
邏輯刪除 @Column(isLogicDelete=true) Integer/Boolean/DateTime
樂觀鎖 @Column(version=true) 版本+1並檢測
多租戶 @Column(tenantId=true) 自動租戶條件
資料脫敏 @ColumnMask(Masks.MOBILE_PHONE) 查詢自動脫敏
多資料來源 @Table(dataSource="ds2") DataSourceKey.use()
欄位加密 @Column(typeHandler=AesTypeHandler.class) 儲存加密

詳見 advanced-features.md


最佳實踐

推薦: Lambda語法、APT表定義類、分頁傳totalRow、when()動態條件

避免: setRaw()字串拼接(SQL隱碼攻擊)、Java專案引入Kotlin模組

🤖 AI 評測

這個技能包質量不錯,文件結構清晰、覆蓋全面,從基礎用法到高階特性都有詳細說明,程式碼示例豐富實用。對於想深入學習 MyBatis-Flex 框架的開發者來說是一份較為完整的參考資料。優點是內容詳盡、分類清晰;可改進的地方是缺少常見問題解答和最佳實踐案例。

📊 多維度評分

適應性4.1
規範性4.5
有效性4.7
可靠性4.7
可信度5

📁 包含檔案 (10 個)

📄 SKILL.md 5.6 KB
📄 references/advanced-features.md 20.5 KB
📄 references/codegen-and-apt.md 15.7 KB
📄 references/db-row-and-basemapper.md 19.2 KB
📄 references/entity-annotations.md 11 KB
📄 references/kotlin-guide.md 5 KB
📄 references/other-features.md 12.5 KB
📄 references/querywrapper-advanced.md 17.3 KB
📄 references/relations-query.md 13.7 KB
📄 references/service-layer.md 6.7 KB