ScriptsJul 1, 2026·3 min read

MyBatis-Plus — Enhanced ORM Toolkit for MyBatis

A powerful enhancement layer for MyBatis that provides built-in CRUD operations, code generation, pagination, and query wrappers while remaining fully compatible with standard MyBatis.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
MyBatis-Plus Overview
Direct install command
npx -y tokrepo@latest install 2db5b0ae-7527-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

MyBatis-Plus (MP) extends MyBatis with zero-boilerplate CRUD, type-safe query builders, and automatic code generation. It eliminates the need to write repetitive mapper XML for standard operations while preserving full access to native MyBatis when custom SQL is required.

What MyBatis-Plus Does

  • Provides BaseMapper with 17 built-in CRUD methods requiring no XML or annotations
  • Offers LambdaQueryWrapper for type-safe, refactor-friendly query construction
  • Includes a code generator that produces entity, mapper, service, and controller layers
  • Handles physical pagination with dialect-aware plugins for MySQL, PostgreSQL, Oracle, etc.
  • Supports logical delete, optimistic locking, and automatic field filling

Architecture Overview

MyBatis-Plus wraps the standard MyBatis SqlSession and injects pre-built MappedStatements for each BaseMapper method at startup. The MybatisPlusInterceptor plugin chain handles pagination, optimistic locking, and multi-tenancy by rewriting SQL before execution. All enhancements are additive; existing MyBatis XML mappers and annotations continue to work unchanged.

Self-Hosting & Configuration

  • Add the mybatis-plus-spring-boot3-starter to your Maven or Gradle project
  • Configure your datasource in application.yml as with standard Spring Boot
  • Entity classes use @TableName and @TableId annotations to map to tables
  • The pagination plugin must be registered as a bean to enable automatic paging
  • Code generator is available via mybatis-plus-generator with template engine support

Key Features

  • Zero-XML CRUD through BaseMapper and IService interfaces
  • Lambda query wrappers prevent column-name typos at compile time
  • Built-in pagination plugin with total count and page metadata
  • Multi-tenant isolation via SQL interception (schema or column-level)
  • Active Record pattern support for those who prefer entity-centric operations

Comparison with Similar Tools

  • JPA / Hibernate — full ORM with entity state management; MP is a thinner SQL-centric layer
  • jOOQ — type-safe SQL DSL from schema; MP enhances an existing MyBatis setup
  • Spring Data JDBC — simple relational mapping; MP offers richer query builders and code generation
  • Fluent MyBatis — alternative MyBatis enhancer; MP has a larger community and ecosystem

FAQ

Q: Is MyBatis-Plus compatible with existing MyBatis projects? A: Yes. It is designed as a drop-in enhancement. Existing XML mappers and configurations are unaffected.

Q: Does it support multi-datasource setups? A: Yes. The dynamic-datasource module provides annotation-based datasource switching.

Q: Can I still write custom SQL? A: Absolutely. You can use @Select annotations or XML mappers alongside BaseMapper methods.

Q: What databases are supported? A: MySQL, PostgreSQL, Oracle, SQL Server, MariaDB, H2, SQLite, DM, and others via MyBatis dialects.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets