在eclipse中使用mybatis-generator自动创建代码

ps:这个插件不知道是不是要FQ,我是用了VPN
2.写xml配置文件: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 <generatorConfiguration>  
 6 <!-- 数据库驱动-->  
 7     <classPathEntry  location="C:\Users\admin\workspace\prac\mysql-connector-java-5.1.38.jar"/>  
 8     <context id="DB2Tables"  targetRuntime="MyBatis3">  
 9         <commentGenerator>  
10             <property name="suppressDate" value="true"/>  
11             <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
12             <property name="suppressAllComments" value="true"/>  
13         </commentGenerator>  
14         <!--数据库链接URL,用户名、密码 -->  
15         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/db_test" userId="root" password="">  
16         </jdbcConnection>  
17         <javaTypeResolver>  
18             <property name="forceBigDecimals" value="false"/>  
19         </javaTypeResolver>  
20         <!-- 生成模型的包名和位置-->  
21         <javaModelGenerator targetPackage="com.practice.prac.model" targetProject="prac">  
22             <property name="enableSubPackages" value="true"/>  
23             <property name="trimStrings" value="true"/>  
24         </javaModelGenerator>  
25         <!-- 生成映射文件的包名和位置-->  
26         <sqlMapGenerator targetPackage="com.practice.prac.mapping" targetProject="prac">  
27             <property name="enableSubPackages" value="true"/>  
28         </sqlMapGenerator>  
29         <!-- 生成DAO的包名和位置-->  
30         <javaClientGenerator type="XMLMAPPER" targetPackage="com.practice.prac.dao" targetProject="prac">  
31             <property name="enableSubPackages" value="true"/>  
32         </javaClientGenerator>  
33         <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->  
34         <table tableName="user_t" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
35     </context>  
36 </generatorConfiguration>
generatorConfig.xml
 
其中 
1 <classPathEntry  location="C:\Users\admin\workspace\prac\mysql-connector-java-5.1.38.jar"/>
一句中location对应地址存放相应的 mysql-connector jar包。
具体的配置,注释已经写的很清楚了
至于这个xml文件的位置,我是放在src/main/resources目录下,不知道放在其他地方行不行
需要注意的地方是targetProject,直接写项目名称 targetPackages 写对应文件的目录
 
然后右键该xml文件,执行 General MyBatis/iBATIS Artifact就能生成对应的model、mapper和dao了。

 

posted @ 2016-05-06 18:14  三生有幸呵呵哒  阅读(4938)  评论(0编辑  收藏  举报