【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件

具体请参照:

http://blog.csdn.net/fengshizty/article/details/43086833

按照上面博客地址,下载Generator的依赖包:

如下是我的配置文件:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 3 <generatorConfiguration>
 4     <!-- 数据库驱动包位置 -->
 5     <classPathEntry location="C:\Generate\generator\generator\mysql-connector-java-5.1.34.jar" /> 
 6     <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />-->
 7     <context id="DB2Tables" targetRuntime="MyBatis3">
 8         <commentGenerator>
 9             <property name="suppressAllComments" value="true" />
10         </commentGenerator>
11         <!-- 数据库链接URL、用户名、密码 -->
12          <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/testmybatis" userId="root" password="XXXXX"> 
13         <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
14         </jdbcConnection>
15         <javaTypeResolver>
16             <property name="forceBigDecimals" value="false" />
17         </javaTypeResolver>
18         <!-- 生成模型的包名和位置 -->
19         <javaModelGenerator targetPackage="com.zlg.model" targetProject="C:\Generate\generator\generator\src">
20             <property name="enableSubPackages" value="true" />
21             <property name="trimStrings" value="true" />
22         </javaModelGenerator>
23         <!-- 生成的映射文件包名和位置 -->
24         <sqlMapGenerator targetPackage="com.zlg.mapping" targetProject="C:\Generate\generator\generator\src">
25             <property name="enableSubPackages" value="true" />
26         </sqlMapGenerator>
27         <!-- 生成DAO的包名和位置 -->
28         <javaClientGenerator type="XMLMAPPER" targetPackage="com.zlg.dao" targetProject="C:\Generate\generator\generator\src">
29             <property name="enableSubPackages" value="true" />
30         </javaClientGenerator>
31         <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
32         <table tableName="user" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
33         <table tableName="dept" domainObjectName="DeptInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
34         <table tableName="emp" domainObjectName="EmpInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
35         <table tableName="cost" domainObjectName="CostInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
36     </context>
37 </generatorConfiguration>
View Code

根据以上配置文件中的标记位置,修改成你需要的位置,然后运行如下指令(记住用tab键补全命令,这个用过CMD或者Linux都知道)。

运行成功后,就生成了如下文件:

当然,如果你比较懒,可以直接把生成路径设置成你项目的相应位置。

 

此时,你就可以把这些对应的文件拷贝到项目的相关位置了。非常简单,而且以上链接的作者已经写得很详细了。

感谢分享~

posted @ 2016-10-25 22:05  丶会飞的羊  阅读(912)  评论(0编辑  收藏  举报