美文网首页
mybatis-generator 逆向工程的使用(附百度云)

mybatis-generator 逆向工程的使用(附百度云)

作者: 有_味 | 来源:发表于2018-08-07 15:23 被阅读156次

    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">
      

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

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

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

      修改两个属性

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

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

    1. 生成代码

      生成很简单,双击

      mark

    保存 ! 很重要!

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

    但是:src文件夹不能删

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

    完!

    相关文章

      网友评论

          本文标题:mybatis-generator 逆向工程的使用(附百度云)

          本文链接:https://www.haomeiwen.com/subject/vdhavftx.html