MybatisPlus代码生成器配置
时间: 2025-01-13 16:10:29 浏览: 52
### 配置 MyBatis Plus 代码生成器
为了配置 MyBatis Plus 代码生成器,需先引入必要的依赖项。具体来说,在项目的 `pom.xml` 文件中加入如下依赖:
```xml
<!-- 代码生成器 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<!-- 模板引擎 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
```
接着,创建并初始化 FastAutoGenerator 实例来进行详细的配置工作。下面是一个完整的例子展示如何设置各个模块的位置以及输出路径。
```java
FastAutoGenerator.create("jdbc:mysql://localhost:3306/db_name", "username", "password")
.globalConfig(builder -> builder.author("authorName").outputDir("D:\\"))
.packageConfig(new PackageConfig.Builder()
.parent("com.example.project")
.moduleName("sys")
.entity("pojo")
.service("service")
.serviceImpl("service.impl")
.mapper("mapper")
.xml("mapper.xml")
.controller("controller")
.other("other")
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:/"))
.build())
.strategyConfig(strategy -> strategy.addInclude("table_name") // 表名
.addTablePrefix("t_", "c_")) // 前缀过滤
.templateEngine(new VelocityTemplateEngine()) // 使用Velocity作为模板引擎
.execute();
```
上述代码片段展示了怎样通过调用不同的构建器方法来自定义全局配置、包结构、策略选项等内容,并最终执行代码生成功能[^3]。
值得注意的是,如果遇到分页插件不兼容的情况,则可能需要调整版本号至较低版次如 3.4.0 来解决问题[^5]。
阅读全文
相关推荐



















