生成步骤:
- 在pom.xml中添加插件
<!--mybatis Generator插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.0</version>
<dependencies>
<dependency>
<groupId>com.dm</groupId>
<artifactId>dmjdbc8</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose> <!--允许移动生成的文件-->
<overwrite>true</overwrite> <!--允许覆盖生成的文件-->
</configuration>
</plugin>
- 对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="bootstrap.yml"/> -->
<!-- 数据库驱动 -->
<!-- <classPathEntry location="D:\DevSoftware\DM\drivers\jdbc\DmJdbcDriver18.jar"/>-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 注释控制 -->
<commentGenerator>
<!-- 不希望生成的注释中包含时间戳 -->
<property name="suppressDate" value="true"/>
<!-- 添加 db 表中字段的注释 -->
<property name="addRemarkComments" value="false"/>
<!-- 是否去除自动生成的注释 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接 -->
<jdbcConnection driverClass="dm.jdbc.driver.DmDriver"
connectionURL="jdbc:dm://ip:5236/MYTEST"
userId="SYSDBA"
password="123456">
</jdbcConnection>
<!-- <jdbcConnection driverClass="com.mysql.jdbc.Driver"-->
<!-- connectionURL="jdbc:mysql://ip:3306/mytest"-->
<!-- userId="root"-->
<!-- password="123456">-->
<!-- </jdbcConnection>-->
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<!-- <javaTypeResolver >-->
<!-- <property name="forceBigDecimals" value="false" />-->
<!-- </javaTypeResolver>-->
<!-- Entity Java Class -->
<javaModelGenerator targetPackage="c.b.p.a.a.domain.upreport" targetProject="../assets-upreport/src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- Mapper XML -->
<sqlMapGenerator targetPackage="mapper.upreport" targetProject="../assets-upreport/src/main/resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- Mapper 接口 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="c.b.p.a.a.mapper.upreport"
targetProject="../assets-upreport/src/main/java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- 需要生成的数据库表 -->
<table schema="MYTEST" tableName="MY_TEST" domainObjectName="MyTest" enableCountByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false" enableUpdateByExample="false">
</table>
</context>
</generatorConfiguration>
- 找到maven中的mybatis generator插件然后双击mybatis-generator:generate