美文网首页
13|第十三课:逆向工程

13|第十三课:逆向工程

作者: 木头amo | 来源:发表于2019-03-02 05:44 被阅读6次

    一、历史回顾

    (一)、历史回顾

    图示

    二、Mybatis逆向工程详解

    1、逆向工程

    表、类、接口、mapper.xml四者密切相关。因此,当知道一个的时候,其他三个应该可以自动生成。

    2、根据表 ---> 其他三个

    实现步骤:

    a、jar

    mybatis-generator-core.jar

    b、逆向工程配置文件

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

    <generatorConfiguration>

    <!--数据库驱动-->

    <!--

    <classPathEntry location="classpath:mysql-connector-java-5.1.36.jar"/>

    -->

    <context id="DB2Tables" targetRuntime="MyBatis3">

    <!-- 生成注释 -->

    <commentGenerator>

    <property name="suppressDate" value="true"/>

    <!-- 是否压制注释(是否有注释) -->

    <property name="suppressAllComments" value="true"/>

    </commentGenerator>

    <!--数据库链接地址账号密码-->

    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/ssm" userId="root" password="root">

    </jdbcConnection>

    <javaTypeResolver>

    <!--forceBigDecimals属性值:

    true:把数据表中的DECIMAL和NUMERIC类型,解析为JAVA代码中的java.math.BigDecimal类型

    false(默认):把数据库表中的DECIMAL和NUMERIC类型,解析为JAVA代码中的Integer类型

    -->

    <property name="forceBigDecimals" value="false"/>

    </javaTypeResolver>

    <!--生成Model类存放位置-->

    <!-- 

    targetPackage:实体类所在的包路径

    targetProject:实体类所在的位置

    -->

    <javaModelGenerator targetPackage="com.test.entity" targetProject="src">

    <property name="enableSubPackages" value="true"/>

    <!-- 

    trimStrings属性值:

    true:对数据库查询结果进行trim操作

    false(默认):不进行trim操作

    -->

    <property name="trimStrings" value="true"/>

    </javaModelGenerator>

    <!--生成映射文件存放位置-->

    <sqlMapGenerator targetPackage="com.test.mapper" targetProject="src">

    <property name="enableSubPackages" value="true"/>

    </sqlMapGenerator>

    <!--生成Dao类(接口)存放位置-->

    <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.mapper" targetProject="src">

    <property name="enableSubPackages" value="true"/>

    </javaClientGenerator>

    <!--生成对应表及类名-->

    <!--

    <table tableName="message"

      domainObjectName="Messgae"

      enableCountByExample="false"

      enableUpdateByExample="false"

      enableDeleteByExample="false"

      enableSelectByExample="false"

      selectByExampleQueryId="false">

    </table>

    -->

    <table tableName="person"></table>

    <table tableName="card"></table>

    <table tableName="city"></table>

    </context>

    </generatorConfiguration>

    c、测试类

    相关文章

      网友评论

          本文标题:13|第十三课:逆向工程

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