mybatis-plus README

项目的 README,来自 github.com/baomidou/mybatis-plus。合并为一个 markdown 文件: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)

正在搜索数据库…

这是什么?MyBatis-Plus 是 MyBatis 的增强工具包。MyBatis 是一个 Java 的 SQL 映射框架,MyBatis-Plus 在它之上提供了开箱即用的功能,用来简化数据库开发、少写很多代码。
那我是用它替代 MyBatis,还是在 MyBatis 上面加一层用?是在 MyBatis 之上用的。它和 MyBatis 完全兼容,启动时会自动完成配置,所以你现有的 MyBatis 代码照常运行,同时还能用到它带来的额外功能。
我怎么把它加到项目里?用 Maven 或 Gradle 添加依赖即可,官方为 Spring Boot 2、3、4 都提供了 starter。然后让你的 mapper 接口继承 BaseMapper,它里面的方法就可以直接使用了。
它支持哪些 Java 和 Spring Boot 版本?starter 覆盖 Spring Boot 2、3 和 4:Spring Boot 2 这条线在 JDK 8 上运行,Spring Boot 3 和 4 则需要 JDK 11 及以上。目前的版本在 3.5.x 系列。
使用上有什么限制需要我知道的吗?README 中警告:违法违规项目不得使用本工具,否则后果自负。高级功能单独放在一个叫 Mybatis-Mate 的企业版里,需要通过微信联系获取。
每个查询我还得自己写 SQL 吗?不用。mapper 继承 BaseMapper 之后,就自带了一套数据库操作的通用接口;自定义的查询条件也不用手写 SQL,通过灵活的条件构造器(where 封装)和 Lambda 风格的 API 就能拼出来。
分页是怎么实现的?是自动的:分页功能以内置插件的形式提供,README 把它和代码生成、条件查询构造器一起列为核心功能。
它能根据我的表生成那些重复的样板代码吗?可以。它内置了一个高度可定制的代码生成器,README 里还专门链接了一份单独的 Code Generator(代码生成器)指南。
它能防 SQL 注入吗?能,SQL 注入防护是它的内置功能之一。
有哪些类似的项目?mall, Mybatis-PageHelper, druid, ent, diesel, APIJSON, vhr, flyway
作者
baomidou
大小
33.6 MB
星标
17.5K
时长
10年
提交 · 90 天