xdxxdx
www.xdxxdxxdx.com

我们可以使用mybatis-generator-core这个工具将数据库对象转换成mybatis对象,具体步骤如下。

1.mybatis-generator-core下载

下载地址:http://download.csdn.net/download/u012909091/7206091

2.解压文件,解压后的目录如下。

打开其中的lib文件夹,其目录如下:

3.修改generatorConfig.xml配置文件

主要修改一些基本信息,包括数据库连接语句,用户名,密码,生成的实体及xml文件还要dao要放置的地方,还要就是表名称和对应的实体名称。具体配置如下。

 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="mysql-connector-java-5.1.25-bin.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://39.107.96.196/blog" userId="xdx" password="xxxxx">  
16         </jdbcConnection>  
17         <javaTypeResolver>  
18             <property name="forceBigDecimals" value="false"/>  
19         </javaTypeResolver>  
20         <!-- 生成模型的包名和位置-->  
21         <javaModelGenerator targetPackage="com.xdx.entity" targetProject="src">  
22             <property name="enableSubPackages" value="true"/>  
23             <property name="trimStrings" value="true"/>  
24         </javaModelGenerator>  
25         <!-- 生成映射文件的包名和位置-->  
26         <sqlMapGenerator targetPackage="com.xdx.entity" targetProject="src">  
27             <property name="enableSubPackages" value="true"/>  
28         </sqlMapGenerator>  
29         <!-- 生成DAO的包名和位置-->  
30         <javaClientGenerator type="XMLMAPPER" targetPackage="com.xdx.entity" targetProject="src">  
31             <property name="enableSubPackages" value="true"/>  
32         </javaClientGenerator>  
33         <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->  
34         <table tableName="t_admin" domainObjectName="TAdmin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
35     </context>  
36 </generatorConfiguration>  

大家可以对照上述配置自己去修改。

4.在命令行中先进入lib目录,然后执行如下指令,即可生成我们想要的实体文件了。

Java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

5.我们再回到src目录下,就可以看到生成的实体文件了

 

把他们拷到我们的项目里面就行了。

posted on 2018-02-01 23:12  xdxxdx  阅读(353)  评论(0编辑  收藏  举报