mybatis-generator 逆向工程的使用

mybatis-generator 逆向工程的使用

作用 :

此工具是很好的MyBatis自动代码生成工具.简单的说就是通过数据库的表生成实体bean和mapping文件.

此工具的优势:

不需要在IDE中运行,简单修改工具中的配置即可!

本文字不多,为避免坑,请自习阅读 ! ! ! ~~~

使用步骤

1. 下载你想工程工具包:

  1. 下载你想工程工具(百度云)

    链接: https://pan.baidu.com/s/1pyfKOgWB7WIqTyW0h-U_hw 密码: fjp4
    
    大小:4M
  2. 下载好后是这样的

    mark

2.修改相关的数据参数

代码:

<?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">
<generatorConfiguration>
   <!-- 数据库驱动包位置 -->
    <classPathEntry  location="mysql-connector-java-5.1.25-bin.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>            
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!-- 数据库链接URL、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/ssmdb" userId="root" password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator targetPackage="test.domain" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成的映射文件包名和位置 -->
        <sqlMapGenerator targetPackage="test.mapping" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="test.IDao" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- ??????? tableName????????Ȗ??????????? domainObjectName?????????-->

        <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
        <table tableName="base_dict" domainObjectName="BaseDict" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="customer" domainObjectName="Customer" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

    </context>
</generatorConfiguration>

要修改的地方:

  1. 修改数据库连接信息

           <!-- 数据库链接URL、用户名、密码 -->
           <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/ssmdb" userId="root" password="root">

    这里填的是你数据库连接路径,和你的数据库的名字账号,密码 .

  2. 配置数据库表和映射参数

           <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
           <table tableName="base_dict" domainObjectName="BaseDict" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    

    修改两个属性

    tableName: 这里是你的数据库的表的名称

    domainObjectName: 这里是你生成实体类的名称.

  3. 生成代码

    生成很简单,双击

    mark

    保存 ! 很重要!

    注意: 在生成的时候 , 会覆盖上次生成的代码,为避免覆盖出错,建议先删除src下的文件

    但是:src文件夹不能删

  4. 拷贝到工程目录下,再根据自己的需求修和使用.

完!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值