eclipse下用maven插件+Mabatis-generator生成mybatis的文件

1. 配置Maven pom.xml 文件

在pom.xml增加以下插件:

 1  <build>
 2        </plugins>
 3             ...
 4             <plugin>
 5                 <groupId>org.mybatis.generator</groupId>
 6                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 7                 <version>1.3.2</version>
 8                 <configuration>
 9                     <verbose>true</verbose>
10                     <overwrite>true</overwrite>
11                 </configuration>
12             </plugin>
13             ...
14         </plugins>
15     </build>

配置好Maven插件,下面需要配置插件需要mybatis-generator的配置文件

2. 配置mybatis-generator的配置文件

添加配置文件到resource下:

generatorConfig.xml的内容:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3          PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4          "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 
 6 <generatorConfiguration>
 7     <!-- ojdbc的jar包 -->
 8     <classPathEntry
 9         location="E:/maven/mvn_repository/com/oracle/ojdbc14/14/ojdbc14-14.jar" />
10     <context id="my" targetRuntime="MyBatis3">
11         <commentGenerator>
12             <property name="suppressDate" value="false" />
13             <property name="suppressAllComments" value="true" />
14         </commentGenerator>
15         <!-- 数据库连接信息 -->
16         <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
17             connectionURL="jdbc:oracle:thin:@192.168.1.112:1521:orcl" userId="KY"
18             password="KY" />
19             <!-- model生成路径 -->
20         <javaModelGenerator targetPackage="com.dg.bean"
21             targetProject="E:/MyWorkspace/ssmdemo/src/main/java">
22             <property name="enableSubPackages" value="true" />
23             <property name="trimStrings" value="true" />
24         </javaModelGenerator>
25         <!-- 映射xml文件生成路径 -->
26         <sqlMapGenerator targetPackage="com.dg.mapping"
27             targetProject="E:/MyWorkspace/ssmdemo/src/main/java">
28             <property name="enableSubPackages" value="true" />
29         </sqlMapGenerator>
30         <!-- 和xml文件关联的dao生成路径(生成文件名默认是***Mapper.java,习惯将其改名成 ***Dao.java) -->
31         <javaClientGenerator targetPackage="com.dg.dao"
32             targetProject="E:/MyWorkspace/ssmdemo/src/main/java" type="XMLMAPPER">
33             <property name="enableSubPackages" value="true" />
34         </javaClientGenerator>
35 
36         <!-- 目标表,如果有多个表就将此段拷贝分别配置 -->
37         <table tableName="ORDER_INFO" domainObjectName="OrderInfoBean"
38             enableCountByExample="false" enableUpdateByExample="false"
39             enableDeleteByExample="false" enableSelectByExample="false"
40             selectByExampleQueryId="false">
41         </table>
42     </context>
43 </generatorConfiguration>

3. 生成代码

在eclipse 中,选择pom.xml文件,击右键先择Run AS——>Maven Build… ——>在Goals框中输入:mybatis-generator:generate,

maven会先下载插件,然后生成代码。

 

看效果:

 

posted @ 2018-08-01 11:51  Python研究者  阅读(3138)  评论(0编辑  收藏  举报