共计 3075 个字符,预计需要花费 8 分钟才能阅读完成。
pom.xml
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
</dependency>
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties resource="generatorConfig.properties"/>
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="runtimeCatalog" value="true"/>
<plugin type="${mapper.plugin}">
<property name="mappers" value="${mapper.Mapper}"/>
</plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<jdbcConnection driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.url}"
userId="${jdbc.user}"
password="${jdbc.password}">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
<property name="useJSR310Types" value="true"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/>
<sqlMapGenerator targetPackage="${targetMapperPackage}" targetProject="${targetResourcesProject}"/>
<javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}"
type="XMLMAPPER"/>
<!-- 表配置 tableName 表名 domainObjectName java 类名,首字母必须大写,否则报字符串越界谬误 -->
<!-- Base -->
<!-- <table tableName="base_app" domainObjectName="base.AppDao">-->
<!-- <generatedKey column="id" sqlStatement="Mysql" identity="true"/>-->
<!-- <columnOverride column="status" javaType="com.hehewang.hhw.app.common.enums.dao.SimpleStatusEnum"/>-->
<!-- <columnOverride column="platform" javaType="com.hehewang.hhw.app.common.enums.dao.AppPlatformEnum"/>-->
<!-- </table>-->
</context>
</generatorConfiguration>
generatorConfig.properties
# 数据库配置
jdbc.driverClass = com.mysql.cj.jdbc.Driver
jdbc.url = jdbc:mysql://192.168.1.201:13306/hhw_dev?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
jdbc.user = hhw_dev
jdbc.password = mysql:hhw_dev:4f0LFwIPSp8Iyogk
#c3p0
jdbc.maxPoolSize = 50
jdbc.minPoolSize = 10
jdbc.maxStatements = 100
jdbc.testConnection = true
# 通用 Mapper 配置
mapper.plugin = tk.mybatis.mapper.generator.MapperPlugin
mapper.Mapper = com.hehewang.hhw.app.common.util.ApiMapper
# domain
targetModelPackage = com.hehewang.hhw.app.common.dao
# mapper
targetMapperPackage = com.hehewang.hhw.app.common.mapper
targetJavaProject = app-common/src/main/java
targetResourcesProject = app-common/src/main/resources
MybatisGeneratorRun.java
package xxx.app.common.generator;
import org.mybatis.generator.api.ShellRunner;
import java.io.IOException;
public class MybatisGeneratorRun
{public static void main(String[] args) throws IOException, InterruptedException
{
// 生成 dao 文件
args = new String[] { "-configfile", "app-common/src/test/resources/generatorConfig.xml", "-overwrite"};
ShellRunner.main(args);
// 备份 TODO Mysql 服务器降级
// MySqlDumpTest dump = new MySqlDumpTest();
// dump.before();
// dump.bumpSchema();// 构造
// dump.bumpData();// 数据}
}
正文完