利用mybatis插件反向生成javabean

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>

简单实用,更多的时间得到释放。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值