Scripts2026年7月1日·1 分钟阅读

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 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
MyBatis-Plus Overview
直接安装命令
npx -y tokrepo@latest install 2db5b0ae-7527-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产