代码生成器(新) | MyBatis-Plus (baomidou.com)
代码生成器3.5.2 建议不如用idea-easycode插件,不过需要找模板如果要配置相关swagger注解的话
springboot+mybatis-plus
坑(对于只想新开项目专门做生成器来说):
- 需额外引入以下依赖(官网提了但是没说在哪里找,需要到旧生成器以及搭建springboot那块找)
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.5.0.0</version>
</dependency>
-
不支持oracle(新版目前尝试不支持,有能成功的老哥麻烦教下) -
需引入application.properties配置文件配置数据源(因为pom中引入了mysql、oracle包,不配置会提示找不到datasource)
快速入门代码参考官网即可:
mybatis-plus 代码生成器(3.5.2) - Cyrui_13 - 博客园 (cnblogs.com)
FastAutoGenerator.create("url", "username", "password")
.globalConfig(builder -> {
builder.author("baomidou")
.enableSwagger()
.fileOverride()
.outputDir("D://");
})
.packageConfig(builder -> {
builder.parent("com.baomidou.mybatisplus.samples.generator")
.moduleName("system")
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://"));
})
.strategyConfig(builder -> {
builder.addInclude("t_simple")
.addTablePrefix("t_", "c_");
})
.templateEngine(new FreemarkerTemplateEngine())
.execute();
数据源配置:可以通过idea的easycode看示例。
#设置数据库连接配置(mysql8)
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai
#spring.datasource.username=******
#spring.datasource.password=*******
#oracle设置数据库连接配置(service)
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//ip:port/database
spring.datasource.username=****
spring.datasource.password=***
oracle url配置:
格式一:jdbc:oracle:thin:@//<host>:<port>/<service_name> 格式二:jdbc:oracle:thin:@<host>:<port>:<SID> 格式三:jdbc:oracle:thin:@<TNSName>
|