MyBatis-Flex: An Elegant MyBatis Enhancement Framework
MyBatis-Flex is a lightweight, high‑performance extension to MyBatis that adds full CRUD, pagination, multi‑table and batch operations while preserving all MyBatis features, supports multi‑datasource relations, recursive queries, and provides extensive annotations such as @Relation for flexible data mapping, with recent v1.4.9 updates and bug fixes.
MyBatis-Flex: An Elegant MyBatis Enhancement Framework
Features
1. Very lightweight
MyBatis-Flex only depends on MyBatis and no other third‑party libraries.
2. Pure enhancement
Supports CRUD, pagination, multi‑table queries, batch operations without losing any MyBatis functionality.
3. High performance
Its architecture delivers 5‑10× faster CRUD performance compared with similar frameworks such as MyBatis‑Plus.
4. Highly flexible
Provides multi‑primary‑key, logical delete, optimistic lock, data masking, encryption, multi‑datasource, sharding, field permissions, multi‑tenant, transaction management, SQL audit, etc., all for free.
Version v1.4.8 added support for the @Relation annotation across data sources, e.g.:
public class Account implements Serializable {
@Id(keyType = KeyType.Auto)
private Long id;
private String userName;
@RelationOneToMany(targetField = "accountId", dataSource="ds2")
private List<Book> books;
//getter setter
}The associated books collection is fetched from the ds2 datasource, allowing Account and Book to reside in different databases.
For a batch of five Account records, the generated SQL looks like:
SELECT `id`, `user_name`, `age` FROM `tb_account`;
SELECT `id`, `account_id`, `title`, `content` FROM `tb_book`
WHERE account_id IN (1,2,3,4,5);Version v1.4.9 introduces recursive relation queries with configurable depth, enabling tree‑like structures such as:
@Table(value = "tb_menu")
public class Menu implements Serializable {
private Long id;
private Long parentId;
private String name;
@RelationOneToMany(selfField = "id", targetField = "parentId")
private List<Menu> children;
//getter setter
}This allows unlimited depth retrieval of child menus.
MyBatis-Flex v1.4.9 changelog
Added recursive query support and depth setting to @Relation.
Enabled @Relation to work with VO/DTO classes.
Supported join scenarios via intermediate tables.
Introduced extraCondition configuration for custom conditions.
Allowed ignoring specific annotations during queries.
Added dialect support for StarRocks database.
Added BaseMapper.updateByMap() method.
Added true/false constant functions to QueryWrapper.
Optimized static constants with final modifier.
Added .editorconfig for consistent code formatting.
Added of() method to UpdateWrapper as a type‑safe alternative.
Refactored BaseMapper documentation generator.
Improved code generator tableDef field ordering.
Fixed SqlServer 2005 dialect query errors.
Fixed type conversion exception in selectListWithRelationsByQueryAs.
Fixed result errors when Relations annotation wraps primitive types.
Fixed code generator listener class configuration issue.
Fixed APT configuration loading issue with Gradle.
Updated documentation for Relations annotation and changelog placement.
Enhanced code generator configuration documentation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
