An Introduction to MyBatis-Flex: Features, Comparison, and Quick‑Start Guide
This article introduces MyBatis‑Flex, a lightweight yet powerful MyBatis enhancement framework, outlines its key features and advantages, compares it with similar tools, presents performance benchmarks, lists supported databases, and provides a step‑by‑step quick‑start tutorial with code examples for Spring Boot integration.
MyBatis‑Flex is a lightweight, high‑performance enhancement to MyBatis that simplifies CRUD operations, offers flexible query building, and supports a wide range of relational databases, aiming to boost developer productivity and reduce boilerplate code.
Key characteristics include its zero third‑party dependencies, ultra‑lightweight SQL parsing, extensive support for multi‑table queries, dynamic tables and schemas, logical deletion, optimistic locking, data auditing, encryption, and multi‑data‑source handling.
A feature‑by‑feature comparison table shows MyBatis‑Flex matching or surpassing MyBatis‑Plus and Fluent‑MyBatis in areas such as pagination, multi‑table joins, total‑count caching, and RPC‑compatible QueryWrapper support.
Performance tests indicate MyBatis‑Flex can be 5‑10× faster than MyBatis‑Plus for single‑record queries, batch queries, pagination, and updates.
The framework supports numerous databases, including MySQL, PostgreSQL, Oracle, SQL Server, ClickHouse, OceanBase, and many others, with the ability to add custom dialects.
Quick‑start steps for a Spring Boot project are provided:
1. Create a table:
CREATE TABLE IF NOT EXISTS `tb_account` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`user_name` VARCHAR(100),
`age` INTEGER,
`birthday` DATETIME
);2. Add Maven dependencies for mybatis-flex-spring-boot-starter , MySQL driver, and HikariCP.
3. Configure the datasource in application.yml :
spring:
datasource:
url: jdbc:mysql://localhost:3306/flex_test
username: root
password: 123456784. Annotate the Spring Boot main class with @MapperScan("com.mybatisflex.test.mapper") and define entity and mapper classes using Lombok and MyBatis‑Flex annotations.
5. Write test code to query data using QueryWrapper and verify the result.
The article concludes with links to official documentation, code generation tools, and encourages readers to explore the framework further.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.