Why MyBatis-Flex Outperforms MyBatis-Plus: Features, Benchmarks, and Quick Start

MyBatis-Flex is a lightweight, high‑performance MyBatis enhancement framework that offers flexible CRUD, powerful query capabilities, extensive database support, and significant speed advantages over MyBatis‑Plus, with detailed feature comparisons, performance benchmarks, and a step‑by‑step quick‑start guide.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Why MyBatis-Flex Outperforms MyBatis-Plus: Features, Benchmarks, and Quick Start
图片
图片

MyBatis-Flex is a lightweight, high‑performance MyBatis enhancement framework that provides a powerful QueryWrapper, supports flexible CRUD without third‑party dependencies, and works with any relational database.

Features of MyBatis‑Flex

1. Lightweight – Apart from MyBatis, it has no other third‑party dependencies. It implements its core through SqlProvider and runs without any SQL parsing, resulting in minimal overhead.

Extremely high performance.

Easy to trace and debug code.

Higher controllability.

2. Flexible – Supports entity CRUD, pagination, and provides a Db + Row tool that allows operations without entity classes, handling multi‑table queries, join queries, and sub‑queries via QueryWrapper.

3. Powerful – Works with any relational database and can be extended via dialects. It supports composite primary keys, logical deletion, optimistic‑lock configuration, data masking, audit, data fill, and more, all through dedicated features.

MyBatis‑Flex vs. Similar Frameworks

Feature Comparison

MyBatis‑Flex matches or exceeds MyBatis‑Plus and Fluent‑MyBatis in basic CRUD, pagination, total‑cache for pagination, multi‑table queries (including FROM, LEFT JOIN, UNION), multi‑data‑source support, multi‑tenant, dynamic table names, and many advanced features such as logical delete and optimistic lock.

Performance Comparison

Single‑record query speed is roughly 5–10× that of MyBatis‑Plus.

Querying 10 records is about 5–10× faster.

Pagination queries are about 5–10× faster.

Data update speed is also 5–10× faster.

Detailed benchmark results are available at https://mybatis-flex.com/zh/intro/benchmark.html .

Supported Databases

MySQL, MariaDB, Oracle (11g and 12c+), DB2, HSQL, SQLite, PostgreSQL, SQLServer (2005+), DM, Xugu, KingbaseES, Phoenix, Gauss, ClickHouse, GBase, GBase‑8s, Oscar, Sybase, OceanBase, OpenGauss, TDengine, Firebird, Derby, etc.

Quick Start

Step 1: Create Database Table

CREATE TABLE IF NOT EXISTS `tb_account` (
    `id` INTEGER PRIMARY KEY auto_increment,
    `user_name` VARCHAR(100),
    `age` INTEGER,
    `birthday` DATETIME
);

INSERT INTO tb_account(id, user_name, age, birthday)
VALUES (1, '张三', 18, '2020-01-11'),
       (2, '李四', 19, '2021-03-21');

Step 2: Add Maven Dependencies

<dependencies>
    <dependency>
        <groupId>com.mybatis-flex</groupId>
        <artifactId>mybatis-flex-spring-boot-starter</artifactId>
        <version>1.5.3</version>
    </dependency>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
    </dependency>
    <!-- for test only -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Step 3: Configure DataSource (application.yml)

# DataSource Config
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/flex_test
    username: root
    password: 12345678

Step 4: Define Entity and Mapper

@Data
@Table("tb_account")
public class Account {
    @Id(keyType = KeyType.Auto)
    private Long id;
    private String userName;
    private Integer age;
    private Date birthday;
}

public interface AccountMapper extends BaseMapper<Account> { }

Step 5: Use the Mapper

import static com.mybatisflex.test.entity.table.AccountTableDef.ACCOUNT;

@SpringBootTest
class MybatisFlexTestApplicationTests {
    @Autowired
    private AccountMapper accountMapper;

    @Test
    void contextLoads() {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .select()
                .where(ACCOUNT.AGE.eq(18));
        Account account = accountMapper.selectOneByQuery(queryWrapper);
        System.out.println(account);
    }
}

The above example demonstrates how MyBatis‑Flex automatically generates table definitions (e.g., ACCOUNT) via annotation processing, enabling concise and type‑safe queries.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavadatabaseSpring BootORMMyBatis-Flex
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.