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/数据库/实体类等关键词


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>

更多技能请访问小葱技能站7w4.net。

@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