Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 1, 2026·3 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
MyBatis-Plus Overview
Commande d'installation directe
npx -y tokrepo@latest install 2db5b0ae-7527-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires