MyBatis-Plus 是一个 MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

趋势

Mybatis-Plus-Logo

Born To Simplify Development

code style code style code style maven

企业版 Mybatis-Mate 高级特性

添加 微信 wx153666 备注进 mp 群

不允许非法项目使用,后果自负

Special user

aizuda-Logo mall4j-Logo

What is MyBatis-Plus?

MyBatis-Plus is a powerful and enhanced toolkit of MyBatis for simplifying development. It provides efficient, and out-of-the-box features (such as code generation, conditional query builders, pagination plugins...), effectively saving development time

Links

Features

  • Fully compatible with MyBatis
  • Auto configuration on startup
  • Out-of-the-box interfaces for operate database
  • Powerful and flexible where condition wrapper
  • Multiple strategy to generate primary key
  • Lambda-style API
  • Almighty and highly customizable code generator
  • Automatic paging operation
  • SQL Inject defense
  • Support active record
  • Support pluggable custom interface
  • Build-in many useful extensions

Getting started

Add MyBatis-Plus dependency

Latest Version: Maven Central

Choose the starter for your Spring Boot version and replace Latest Version with the MyBatis-Plus version you want to use.

Spring Boot 4

Requires MyBatis-Plus 3.5.13 or later.

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-spring-boot4-starter</artifactId>
    <version>Latest Version</version>
</dependency>

Gradle:

implementation 'com.baomidou:mybatis-plus-spring-boot4-starter:Latest Version'

Test dependency (optional)

To write tests with @MybatisPlusTest, add the matching test starter using the same version as the starter above.

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-spring-boot4-starter-test</artifactId>
    <version>Latest Version</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'com.baomidou:mybatis-plus-spring-boot4-starter-test:Latest Version'

Spring Boot 3

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
    <version>Latest Version</version>
</dependency>

Gradle:

implementation 'com.baomidou:mybatis-plus-spring-boot3-starter:Latest Version'

Test dependency (optional)

To write tests with @MybatisPlusTest, add the matching test starter using the same version as the starter above.

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-spring-boot3-starter-test</artifactId>
    <version>Latest Version</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'com.baomidou:mybatis-plus-spring-boot3-starter-test:Latest Version'

Spring Boot 2

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>Latest Version</version>
</dependency>

Gradle:

implementation 'com.baomidou:mybatis-plus-boot-starter:Latest Version'

Test dependency (optional)

To write tests with @MybatisPlusTest, add the matching test starter using the same version as the starter above.

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter-test</artifactId>
    <version>Latest Version</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'com.baomidou:mybatis-plus-boot-starter-test:Latest Version'

SQL parser dependency (optional)

Since MyBatis-Plus 3.5.9, plugins that parse SQL, such as the pagination plugin, require one of the following parser modules. Choose one module matching your JDK and required JSqlParser version, and use the same MyBatis-Plus version as the starter.

The JSqlParser versions below reflect the dependency configuration in the current repository. For other MyBatis-Plus releases, refer to the dependencies of that release.

MyBatis-Plus module JSqlParser version JDK requirement
mybatis-plus-jsqlparser 5.4 JDK 11+
mybatis-plus-jsqlparser-5.2 5.2 JDK 11+
mybatis-plus-jsqlparser-5.0 5.0 JDK 11+
mybatis-plus-jsqlparser-4.9 4.9 JDK 8+

The following example uses mybatis-plus-jsqlparser. For another JSqlParser version, replace the module name with the corresponding module from the table above.

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-jsqlparser</artifactId>
    <version>Latest Version</version>
</dependency>

Gradle:

implementation 'com.baomidou:mybatis-plus-jsqlparser:Latest Version'

Extend the BaseMapper interface

public interface UserMapper extends BaseMapper<User> {

}

Use it

List<User> userList = userMapper.selectList(
        new QueryWrapper<User>()
                .lambda()
                .ge(User::getAge, 18)
);

MyBatis-Plus will execute the following SQL:

SELECT * FROM user WHERE age >= 18

This showcase is just a small part of MyBatis-Plus features. If you want to learn more, please refer to the documentation.

License

MyBatis-Plus is under the Apache 2.0 license. See the Apache License 2.0 file for details.

关于
An powerful enhanced toolkit of MyBatis for simplify development
17.5 k
4.4 k
80
语言
Java
Kotlin
FreeMarker
98.45%
1.27%
0.27%