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

MyBatis-Flex is a lightweight, high‑performance MyBatis enhancement that offers flexible CRUD, powerful query wrappers, extensive database support, and speed improvements of up to ten times over MyBatis‑Plus, with a step‑by‑step Spring Boot integration guide.

Top Architect
Top Architect
Top Architect
Why MyBatis-Flex Beats MyBatis-Plus: Features, Benchmarks, and Quick Start Guide

What Is MyBatis‑Flex?

MyBatis‑Flex is an elegant MyBatis enhancement framework that is extremely lightweight, highly performant, and very flexible. It can connect to any relational database and its built‑in QueryWrapper dramatically reduces the amount of SQL you need to write while lowering the risk of errors.

Key Features

Lightweight : No third‑party dependencies, no interceptors, and no SQL parsing, resulting in very high performance and easy debugging.

Flexible : Supports entity CRUD, pagination, Db + Row utilities for operations without entities, and a powerful QueryWrapper for multi‑table, join, and union queries.

Powerful : Works with any relational DB, supports composite primary keys, logical delete, optimistic lock, data desensitization, audit, auto‑fill, field encryption, multi‑tenant, dynamic table names, and more.

Feature Comparison with Other Frameworks

Feature

MyBatis‑Flex

MyBatis‑Plus

Fluent‑MyBatis

Basic CRUD on entity

Pagination

Pagination cache

No‑SQL‑parse pagination

Multi‑table from

Join (left, inner, etc.)

Union / Union All

Composite primary key

Logical delete

Optimistic lock

SQL audit

Data fill

✔️ (paid)

Data desensitization

✔️ (paid)

Field encryption

✔️ (paid)

Dynamic schema

Performance Comparison

Single‑record query is about 5‑10× faster than MyBatis‑Plus.

Querying 10 records is about 5‑10× faster.

Pagination speed is about 5‑10× faster.

Update operations are about 5‑10× faster.

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

Supported Databases

Database

Description

MySQL

MySQL database

MariaDB

MariaDB database

Oracle 11g and below

Oracle 11g

Oracle 12c and above

Oracle 12c

DB2

DB2 database

HSQL

HSQL database

SQLite

SQLite database

PostgreSQL

PostgreSQL database

SQLServer 2005

SQLServer2005 database

SQLServer

SQLServer database

ClickHouse

ClickHouse database

Quick Start Guide

Step 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
);

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>
</dependencies>

Step 3 – Configure DataSource (application.yml)

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 – Write a Test

@SpringBootTest
class MybatisFlexTest {
    @Autowired
    private AccountMapper accountMapper;

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

Console output example:

Account(id=1, userName=张三, age=18, birthday=Sat Jan 11 00:00:00 CST 2020)

Where to Learn More

Official documentation and download links are available at https://mybatis-flex.com/ .

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.

databaseSpring BootORMMyBatis-Flex
Top Architect
Written by

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.

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.