mybatis-plus README

The project's README from github.com/baomidou/mybatis-plus. As one markdown file: README.md.

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

Features

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.

mybatis-plus (baomidou/mybatis-plus)

Searching Database…

What is this?MyBatis-Plus is an enhancement toolkit for MyBatis, the Java SQL mapping framework. It adds out-of-the-box features on top of MyBatis to simplify database development and save coding time.
So do I use it instead of MyBatis, or on top of it?On top of it. It is fully compatible with MyBatis and auto-configures at startup, so your existing MyBatis code keeps working while you gain the extra features.
How do I add it to a project?Add the dependency with Maven or Gradle — starters are provided for Spring Boot 2, 3 and 4 — then make your mapper interface extend BaseMapper and its methods are ready to use.
Which Java and Spring Boot versions does it support?Starters target Spring Boot 2, 3 and 4: the Spring Boot 2 line runs on JDK 8, while Spring Boot 3 and 4 need JDK 11+. Current releases are in the 3.5.x series.
Are there any usage restrictions I should know about?The README warns that illegal projects may not use it, at your own risk. Advanced features are offered separately in an enterprise edition called Mybatis-Mate, reached via WeChat.
Do I still have to write SQL for every query?No. Once your mapper extends BaseMapper you get out-of-the-box interfaces for database operations, and custom filters are composed with a flexible where-condition wrapper and a Lambda-style API instead of hand-written SQL.
How does pagination work?It is automatic: pagination ships as a built-in plugin, listed by the README alongside code generation and conditional query builders as headline features.
Can it generate boilerplate code for my tables?Yes, it includes a highly customizable code generator, and the README links to a separate Code Generator guide for it.
Does it protect against SQL injection?Yes, SQL injection defense is one of its built-in features.
What are similar projects?mall, Mybatis-PageHelper, druid, ent, diesel, APIJSON, vhr, flyway
Creator
baomidou
Size
33.6 MB
Stars
17.5K
Age
10y
Commits · 90 Days