mybatis generator 可以提高开发速度,这个插件可以自动生成代码,创建DAO层相关代码,就像利用HIbernate反相生成一样。
首先是安装插件
1.下载、解压
文件:MyBatisGenerator
地址:http://pan.baidu.com/s/1c0cjDEK
(这个地址不可用的话,百度一下MyBatis_Generator下载。蛮多的)
解压得到这两个文件夹
2.找到eclipse的安装目录
将解压得到的文件夹里面的内容对应放入eclipse里面,重启eclipse!!
3.检查是否安装成功
eclipse左侧空白处 右键New–>other–>mybatis 看有没有插件
这样就安装成功了!!
数据库反向生成实体类
1.配置xml文件
官网文件说明:http://www.mybatis.org/generator/configreference/xmlconfig.html
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<!--
mybatis数据库逆向生成实体类
-->
<generatorConfiguration >
<!--数据库驱动jar -->
<classPathEntry location="D:\MAVEN\Repositories\com\oracle\ojdbc6\11.2.0.1\ojdbc6-11.2.0.1.jar" />
<context id="context1" >
<!--去除注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@192.168.00.000:0000:test"
userId="test"
password="test">
</jdbcConnection>
<!-- 实体 -->
<javaModelGenerator targetPackage="com.test.web.model.ocr" targetProject="bass" />
<!-- xml文件 -->
<sqlMapGenerator targetPackage="com.test.web.mapping.ocr" targetProject="bass" />
<!-- dao -->
<javaClientGenerator targetPackage="com.test.web.dao.ocr" targetProject="bass" type="XMLMAPPER" />
<!-- 数据库对应表格 -->
<!-- <table tableName="B_IDCARD_BACK" domainObjectName="IdcardBack" />
<table tableName="B_IDCARD_FRONT" domainObjectName="IdcardFront" />
<table tableName="B_IDCARD_LEGALITY" domainObjectName="IdcardLegality" />
<table tableName="B_IDCARD_REQUEST" domainObjectName="IdcardRequest" /> -->
<table tableName="B_VERIFY_ACTIVE_MEGLIVE" domainObjectName="VerifyActiveMeglive"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="B_VERIFY_ACTIVE_MEGLIVE_RESP" domainObjectName="VerifyActiveMegliveResp"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>
2.点击文件右键–>Generate Mybatis/iBATis Artifacts
生成的文件
配合powerDesigner里面的物理模型sql语句导出使用,大大提高效率。解放双手!!
去掉Mybatis Generator生成的一堆 example
mybatis generator自动生成的代码里老是有一堆example,虽然说他封装的东西比较多,但是大部分时候并不会用到。如果需要改的时候,在接口和mapper里修改便是了。
<table schema="general" tableName="tb_table_name" domainObjectName="EntityName"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
<property name="useActualColumnNames" value="true"/>
</table>
简单实用,更多的时间得到释放。