转载自 https://blog.csdn.net/hua_faded/article/details/78900780
一、配置Maven pom.xml 文件
在pom.xml增加以下插件:
-
-
<finalName>zsxt</finalName>
-
-
-
<groupId>org.mybatis.generator</groupId>
-
<artifactId>mybatis-generator-maven-plugin</artifactId>
-
-
-
-
<overwrite>true</overwrite>
-
-
-
-
配置好Maven插件,下面需要配置插件需要配置文件
二、在maven项目下的src/main/resources 目录下建立名为 Maven的项目配置文件存放路径如下图:generatorConfig.xml和generator.properties配置文件,
Maven的项目配置文件存放路径如下图:
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">
-
-
-
-
<properties resource="generator.properties"></properties>
-
-
-
<classPathEntry location="${jdbc.driverLocation}"/>
-
-
<context id="default" targetRuntime="MyBatis3">
-
-
-
-
<property name="suppressDate" value="true"/>
-
<property name="suppressAllComments" value="true"/>
-
-
-
-
-
driverClass="${jdbc.driverClass}"
-
connectionURL="${jdbc.connectionURL}"
-
-
password="${jdbc.password}">
-
-
-
-
-
-
<property name="forceBigDecimals" value="false"/>
-
-
-
-
-
-
-
-
<javaModelGenerator targetPackage="com.slx.zsxt.model"
-
targetProject="src/main/java">
-
-
-
<property name="enableSubPackages" value="false"/>
-
-
<property name="constructorBased" value="true"/>
-
-
<property name="trimStrings" value="true"/>
-
-
<property name="immutable" value="false"/>
-
-
-
-
<sqlMapGenerator targetPackage="com.slx.zsxt.mapper"
-
targetProject="src/main/java">
-
<property name="enableSubPackages" value="false"/>
-
-
-
-
-
-
-
-
<javaClientGenerator targetPackage="com.slx.zsxt.dao"
-
targetProject="src/main/java" type="XMLMAPPER">
-
<property name="enableSubPackages" value="true"/>
-
-
-
-
<table tableName="reguser" domainObjectName="User"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
-
<table tableName="adminuser" domainObjectName="Admin"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
<table tableName="configinfo" domainObjectName="Confinfo"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
<table tableName="grade" domainObjectName="Grade"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
<table tableName="gradelog" domainObjectName="Gradelog"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
<table tableName="reginfo" domainObjectName="Reginfo"
-
enableCountByExample="false" enableUpdateByExample="false"
-
enableDeleteByExample="false" enableSelectByExample="false"
-
selectByExampleQueryId="false">
-
-
-
</generatorConfiguration>
generator.propertites代码如下:
-
jdbc.driverLocation=E:\\mvn_home\\mysql\\mysql-connector-java\\5.1.20\\mysql-connector-java-5.1.20.jar
-
jdbc.driverClass=com.mysql.jdbc.Driver
-
jdbc.connectionURL=jdbc:mysql:///zsxt
-
-
三、在Intellij IDEA添加一个“Run运行”选项,使用maven运行mybatis-generator-maven-plugin插件
点击 菜单run中Edit Configurations,会出现
点击+号,选择maven,会出现
在name和Commond line分别填上如上图所示,apply和ok
最后点击generator,生成model,mapper,dao
逆向工程生成结果如下:
在IDEA中使用MyBatis Generator自动生成代码
原文:https://www.cnblogs.com/miracleYu/p/10098664.html