intellj利用 maven自动生成dto,mapper文件

第一步:pom里添加maven依赖

 1 <build>
 2         <plugins>
 3             <plugin>
 4                 <groupId>org.mybatis.generator</groupId>
 5                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 6                 <version>1.3.2</version>
 7                 <configuration>
 8                     <configurationFile>src/main/resources/config/generator.xml</configurationFile>
 9                     <verbose>true</verbose>
10                     <overwrite>true</overwrite>
11                 </configuration>
12                 <executions>
13                 </executions>
14                 <dependencies>
15                     <dependency>
16                         <groupId>org.mybatis.generator</groupId>
17                         <artifactId>mybatis-generator-core</artifactId>
18                         <version>1.3.2</version>
19                     </dependency>
20                 </dependencies>
21             </plugin>
22         </plugins>
23     </build>

第二步:创建generator.xml文件,如下:
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 3         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 4 <generatorConfiguration>
 5     <classPathEntry location="E:mysqlmysql-connector-java-5.1.40-bin.jar"/>
 6     <context id="my" targetRuntime="MyBatis3">
 7         <commentGenerator>
 8             <property name="suppressDate" value="false"/>
 9             <property name="suppressAllComments" value="true"/>
10         </commentGenerator>
11 
12         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
13                         connectionURL=""
14                         userId=""
15                         password=""/>
16 
17         <javaModelGenerator targetPackage="com.haiziwang.yst.api.dbo" targetProject="E:intellijWorkspaceystyst-apisrcmainjava">
18             <property name="enableSubPackages" value="true"/>
19             <property name="trimStrings" value="true"/>
20         </javaModelGenerator>
21 
22         <sqlMapGenerator targetPackage="com.haiziwang.yst.mapper" targetProject="E:intellijWorkspaceystystsrcmain
esources">
23             <property name="enableSubPackages" value="true"/>
24         </sqlMapGenerator>
25 
26         <javaClientGenerator targetPackage="com.haiziwang.yst.mapper" targetProject="E:intellijWorkspaceystystsrcmainjava" type="XMLMAPPER">
27             <property name="enableSubPackages" value="true"/>
28         </javaClientGenerator>
29 
30         <table tableName="stl_balance" domainObjectName="StlBalance"
31                enableCountByExample="false" enableUpdateByExample="false"
32                enableDeleteByExample="false" enableSelectByExample="false"
33                selectByExampleQueryId="false">
34         </table>
35 
36         <table tableName="stl_balance_change" domainObjectName="StlBalanceChange"
37                enableCountByExample="false" enableUpdateByExample="false"
38                enableDeleteByExample="false" enableSelectByExample="false"
39                selectByExampleQueryId="false">
40         </table>
41     </context>
42 </generatorConfiguration>

注意:1.generator.xml的项目位置,放在resources下面

    

   2.<classPathEntry location="E:mysqlmysql-connector-java-5.1.40-bin.jar"/>  mysql驱动

第三步:

  方法一:打开maven Project进入maven项目目录,双击mybiats-generator:generate 运行

出现如下界面表示代码生成成功:

 方法二:添加maven配置如下

点击运行




天道酬勤
原文地址:https://www.cnblogs.com/luohero/p/7283997.html