zoukankan      html  css  js  c++  java
  • 使用逆向工程

    本人使用的逆向工程是在前人的基础上进行第一次的使用,主要用来创建pojo类(domain类).dao层需要的接口,还有就是mapper.xml文件中的一些语句

    使用过程:

    使用idea进行打开以后,

    因为这个逆向工程使用的是一个porject项目,

    因为使用的是直接引入jar包,所以没有使用maven进行管理依赖.

    将其中的一个配置文件

    然后配置的内容大概如下:

    <?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">
        
            <!-- JavaBean 实现 序列化 接口 -->
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin">
            </plugin>
            <!-- genenat entity时,生成toString -->
            <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
            <!-- 自定义查询指定字段  -->
            <plugin type="org.mybatis.generator.plugins.field.FieldsPlugin" />
            <!-- 开启支持内存分页   可生成 支持内存分布的方法及参数  
            <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
            -->
            <!-- generate entity时,生成hashcode和equals方法-->
            <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
             
            <!-- 此处是将Example改名为Criteria 当然 想改成什么都行~    -->      
            <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">  
                <property name="searchString" value="Example$" />
                <!-- 替换后
                <property name="replaceString" value="Criteria" />  
                 -->
                <property name="replaceString" value="Query" />
            </plugin>  
            <!-- 此处是将UserMapper.xml改名为UserDao.xml 当然 想改成什么都行~ --> 
            <plugin type="org.mybatis.generator.plugins.rename.RenameSqlMapperPlugin">  
                <property name="searchString" value="Mapper" />
                <property name="replaceString" value="Dao" />
            </plugin>  
            <!-- 此处是将UserMapper改名为UserDao 接口 当然 想改成什么都行~  -->   
            <plugin type="org.mybatis.generator.plugins.rename.RenameJavaMapperPlugin">  
                <property name="searchString" value="Mapper$" />
                <property name="replaceString" value="Dao" />
            </plugin>  
     
            
            <commentGenerator type="org.mybatis.generator.plugins.comment.MyCommentGenerator">
                <!-- 是否去除自动生成的注释 true:是 : false:否 
                <property name="suppressAllComments" value="true" />
                -->
            </commentGenerator>
            
            <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:3306/pyg_qingmu" userId="root"
                password="root">
            </jdbcConnection>
            <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
                connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg" 
                userId="yycg"
                password="yycg">
            </jdbcConnection> -->
    
            <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 
                NUMERIC 类型解析为java.math.BigDecimal -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
    
            <!-- targetProject:生成PO类的位置 -->
            <javaModelGenerator targetPackage="cn.qingmu.core.pojo"
                targetProject=".src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
                <!-- 从数据库返回的值被清理前后的空格 -->
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!-- targetProject:mapper映射文件生成的位置 -->
            <sqlMapGenerator targetPackage="cn.qingmu.core.dao"
                targetProject=".
    esource">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
            <!-- targetPackage:mapper接口生成的位置 -->
            <javaClientGenerator type="XMLMAPPER"
                targetPackage="cn.qingmu.core.dao"
                targetProject=".src">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
            
    
            <!-- 指定数据库表 -->
            <table schema="" tableName="tb_order" domainObjectName="order.Order"/>
            <table schema="" tableName="tb_order_item" domainObjectName="order.OrderItem"/>
            <table schema="" tableName="tb_address" domainObjectName="address.Address"/>
            <table schema="" tableName="tb_areas" domainObjectName="address.Areas"/>
            <table schema="" tableName="tb_cities" domainObjectName="address.Cities"/>
            <table schema="" tableName="tb_provinces" domainObjectName="address.Provinces"/>
            <table schema="" tableName="tb_content" domainObjectName="ad.Content"/>
            <table schema="" tableName="tb_content_category" domainObjectName="ad.ContentCategory"/>
            <table schema="" tableName="tb_pay_log" domainObjectName="log.PayLog"/>
            <table schema="" tableName="tb_seller" domainObjectName="seller.Seller"/>
            <table schema="" tableName="tb_user" domainObjectName="user.User"/>
            <table schema="" tableName="tb_brand" domainObjectName="good.Brand"/>
            <table schema="" tableName="tb_goods" domainObjectName="good.Goods"/>
            <table schema="" tableName="tb_goods_desc" domainObjectName="good.GoodsDesc"/>
            <table schema="" tableName="tb_specification" domainObjectName="specification.Specification"/>
            <table schema="" tableName="tb_specification_option" domainObjectName="specification.SpecificationOption"/>
            <table schema="" tableName="tb_type_template" domainObjectName="template.TypeTemplate"/>
            <table schema="" tableName="tb_freight_template" domainObjectName="template.FreightTemplate"/>
            <table schema="" tableName="tb_item_cat" domainObjectName="item.ItemCat"/>
            <table schema="" tableName="tb_item" domainObjectName="item.Item"/>
            <table schema="" tableName="tb_seckill_goods" domainObjectName="seckill.SeckillGoods"/>
            <table schema="" tableName="tb_seckill_order" domainObjectName="seckill.SeckillOrder"/>
            
        </context>
    </generatorConfiguration>

    只需要将包名修改一下,然后将数据库的名字进行简单的修改,

    直接运行

    这个文件中的main方法直接运行,然后,就等待就可以生成文件.

    然后将这个文件复制到指定的文件中.

    这里没有对这个逆向工程做深入的研究,只是简单介绍一下用法,

  • 相关阅读:
    第二次作业
    第一次作业——结合三次小作业
    第一次个人编程作业
    uva 10288 gailv
    牛客网第9场多校E(思维求期望)
    hdu6415 记忆化搜索或找规律
    hdu6395 (矩阵快速幂+分块)
    hdu6396(思维+输入挂)
    6354 Everything Has Changed
    牛客网暑期ACM多校训练营(第七场)Bit Compression
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/10661880.html
Copyright © 2011-2022 走看看