zoukankan      html  css  js  c++  java
  • mybatis的逆向工程

    mybatis可以通过逆向工程,生成我们在使用mybatis时可能会用到的70%-80%的方法,下面是逆向工程的链接,自行下载

    链接: https://pan.baidu.com/s/15I47-1wFemu0PMGQQS7QDA 提取码: 6f73

    下载完成后,将其解压后导入myeclipse,其目录中应该有这两个文件。

    其中gereratorConfig.xml中包含了所要生成的配置文件的位置,数据库的表名和字段名,以及jdbc的数据源

    GeneratorSqlmap.java包含了调用xml文件的代码

    我们以student表为例自动生成一个映射文件和接口以及pojo类

    <?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>
        <context id="testTables" targetRuntime="MyBatis3">
            <commentGenerator>
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
            <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:3306/test" userId="root"
                password="root">
            </jdbcConnection>
            <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 
                NUMERIC 类型解析为java.math.BigDecimal -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!-- targetProject:生成PO类的位置 -->
            <!-- targetProject .src是windows的相对路径 -->
            <javaModelGenerator targetPackage="com.oracle.pojo"
                targetProject=".src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
                <!-- 从数据库返回的值被清理前后的空格 -->
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!-- targetProject:mapper映射文件生成的位置 -->
            <sqlMapGenerator targetPackage="com.oracle.mapper" 
                targetProject=".src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
            <!-- targetPackage:mapper接口生成的位置 -->
            <javaClientGenerator type="XMLMAPPER"
                targetPackage="com.oracle.mapper" 
                targetProject=".src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
            </javaClientGenerator>
            
            
            
            <!-- 指定数据库表 -->
            <table tableName="student"></table>
            <!-- <table schema="" tableName="tb_content_category"></table>
            <table schema="" tableName="tb_item"></table>
            <table schema="" tableName="tb_item_cat"></table>
            <table schema="" tableName="tb_item_desc"></table>
            <table schema="" tableName="tb_item_param"></table>
            <table schema="" tableName="tb_item_param_item"></table>
            <table schema="" tableName="tb_order"></table>
            <table schema="" tableName="tb_order_item"></table>
            <table schema="" tableName="tb_order_shipping"></table>
            <table schema="" tableName="tb_user"></table> -->
    
        </context>
    </generatorConfiguration>

    它会在工程中生成一个下面的映射文件和pojo类,我们将其粘贴入mybatis文件中测试运行

    测试结果如下

  • 相关阅读:
    struts2中<s:select>标签的使用
    正则表达式(括号)、[中括号]、{大括号}的区别小结
    解读邮箱正则表达式:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$
    Struts2国际化-getText()方法
    Eclipse的Tomcat热部署,免重启的方法
    hdu 5056Boring count
    纸板上的虚拟现实和代码中的Cardboard
    OC-Protocol实现业务代理
    UVA 11237
    mysql相关日志汇总
  • 原文地址:https://www.cnblogs.com/mhm111/p/11394272.html
Copyright © 2011-2022 走看看