首页
/ 【mybatis-plus-ext】开源下载和安装教程

【mybatis-plus-ext】开源下载和安装教程

2026-02-04 05:21:12作者:戚魁泉Nursing

1、项目介绍

Mybatis-Plus-Ext(MPE)是基于Mybatis-Plus(MP)的增强拓展框架,保留MP全部功能的同时,新增了以下特性:

  • 代码预生成(字段字符串、Mapper、Repository/Service)
  • 自动建表(集成auto-table)
  • 数据自动填充(类似JPA审计功能)
  • 关联查询(类似SQL JOIN操作)
  • 冗余数据自动更新
  • 动态条件查询

2、项目下载位置

通过Maven中央仓库引入依赖:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-ext</artifactId>
    <version>最新版本号</version>
</dependency>

或访问代码托管平台获取源码:

  • Gitee: https://gitee.com/dromara/mybatis-plus-ext
  • GitCode: https://gitcode.com/dromara/mybatis-plus-ext

3、项目安装环境配置

基础环境要求

  • JDK 1.8+
  • Maven 3.0+
  • Spring Boot 2.x(推荐)
  • Mybatis-Plus 3.4.0+

环境依赖示意图

4、项目安装方式

方式一:Spring Boot项目集成

  1. application.yml中添加配置:
mybatis-plus:
  mapper-locations: classpath*:/mapper/**/*.xml
  type-aliases-package: com.example.entity
  1. 启用MPE功能(在主类添加注解):
@EnableMybatisPlusExt
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

方式二:传统SSM项目集成

  1. 配置SqlSessionFactoryBean:
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.ext.spring.MybatisSqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mapperLocations" value="classpath*:/mapper/**/*.xml"/>
</bean>

5、项目处理脚本

自动生成代码示例

public class CodeGenerator {
    public static void main(String[] args) {
        AutoGenerator generator = new AutoGenerator();
        generator.setGlobalConfig(new GlobalConfig()
                .setOutputDir(System.getProperty("user.dir") + "/src/main/java")
                .setAuthor("tangzc"));
        
        generator.setDataSource(new DataSourceConfig()
                .setUrl("jdbc:mysql://localhost:3306/test")
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUsername("root")
                .setPassword("123456"));
        
        generator.execute();
    }
}

自动建表配置

在实体类上添加注解:

@AutoTable(value = "sys_user", comment = "用户表")
public class User {
    @TableId
    private Long id;
    @Column(comment = "用户名", length = 50)
    private String username;
}
登录后查看全文
热门项目推荐
相关项目推荐