1.在pom文件中添加依赖配置
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
2.新建properties文件和xml配置文件
image.png
3.properties文件存储基本信息
#文档测试平台数据库
driver=com.mysql.jdbc.Driver
icc.jdbc.url=jdbc:mysql://localhost:15381/icc?useSSL=false&autoReconnect=true&useAffectedRows=true
icc.jdbc.username=root
icc.jdbc.password=xx-mysql-xx
#entity 包名和 java目录
modelPackage=dataobject
modelProject=src/main/java
#sqlmap包名 和resources目录
sqlPackage=mapper
sqlProject=src/main/java
#mapper包名和 java目录
mapperPackage=mapper
mapperProject=src/main/java
table=icc_config
4.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="dal.properties"/>
<!-- 把路径换成自己的 -->
<classPathEntry
location=".m2/repository/mysql/mysql-connector-java/5.1.25/mysql-connector-java-5.1.25.jar" />
<context id="context1">
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
</commentGenerator>
<jdbcConnection driverClass="${driver}"
connectionURL="${icc.jdbc.url}"
userId="${icc.jdbc.username}"
password="${icc.jdbc.password}" />
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="${modelPackage}"
targetProject="${modelProject}" />
<sqlMapGenerator targetPackage="${sqlPackage}" targetProject="${sqlProject}" />
<javaClientGenerator targetPackage="${mapperPackage}"
targetProject="${mapperProject}" type="XMLMAPPER" />
<!-- 如果需要通配所有表 直接用sql的通配符 %即可 -->
<table schema="" tableName="${table}" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"
>
<!--<columnOverride column="REMARKS" javaType="java.lang.String" jdbcType="VARCHAR"/>-->
</table>
</context>
</generatorConfiguration>
5.点击maven:Plugins->mybatis-generator,双击mybatis-generator:generator即可。如果没有这个插件,刷新试试.
image.png
网友评论