• Mybatis—三剑客之generator使用方法


    三剑客之generator主要用于自动生成POJO实体类
     
    准备素材:
    mybatis-generator-core-1.3.2.jar    
    mysql-connector-java-5.1.26.jar
     
    使用步骤:
    1:配置xml文件
    2:在dos窗口下,进入该xml的目录
    E:Domimyjavajava_publicall_softgeneratorgenerator
    3:执行生成命令
    java -jar mybatis-generator-core-1.3.2.jar -configfile config.xml -overwrite

    补充:(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="E:Domimyjavajava_publicall_softgeneratorgeneratormysql-connector-java-5.1.26.jar"/>
          <context id="DB2Tables" targetRuntime="MyBatis3">
              <!-- optional,旨在创建class时,对注释进行控制 -->
              <commentGenerator>
                 <property name="suppressDate" value="true"/>
                 <property name="suppressAllComments" value="true"/>
             </commentGenerator>
             <!--数据库链接地址账号密码-->
             <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/ebuy" userId="root" password="root">
             </jdbcConnection>
             <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
             <javaTypeResolver>
                 <property name="forceBigDecimals" value="false"/>
             </javaTypeResolver>
            
            <!--生成Model类存放位置-->
             <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
                targetPackage     指定生成的model生成所在的包名
                targetProject     指定在该项目下所在的路径
            -->
             <javaModelGenerator targetPackage="com.demo.entity" targetProject="E:DomieclipseSSMTESTsrcmainjava">
                 <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
                 <property name="enableSubPackages" value="true"/>
                  <!-- 是否对model添加 构造函数 -->
                <property name="constructorBased" value="true"/>
                 <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
                 <property name="trimStrings" value="true"/>
                 <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
                <property name="immutable" value="false"/>
             </javaModelGenerator>
             
             <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
             <sqlMapGenerator targetPackage="com.demo.dao" targetProject="E:DomieclipseSSMTESTsrcmainjava">
                 <property name="enableSubPackages" value="true"/>
             </sqlMapGenerator>
             
             <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
                    type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
                    type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
                    type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
            -->
             <!--生成Dao类存放位置-->
             <javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.dao" targetProject="E:DomieclipseSSMTESTsrcmainjava">
                 <!-- enableSubPackages:是否让schema作为包的后缀 -->
                 <property name="enableSubPackages" value="true"/>
             </javaClientGenerator>
             <!--生成对应表及类名-->
             <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
             <table tableName="shangp" domainObjectName="Shangp" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
             <!--<table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
                 <columnOverride column="detail" jdbcType="VARCHAR" />
                 将数据库中text格式的文本数据转换为varchar,pojo里String类型
                 <columnOverride column="sub_images" jdbcType="VARCHAR" />
             </table>-->
    
        <!-- geelynote mybatis插件的搭建 -->
         </context>
     </generatorConfiguration>
  • 相关阅读:
    学习算法必备数学
    Use NDepend to Measure How SOLID Your Code Is
    使用Docker 快速体验TDengine
    ASP.NET Core 修改开源协议为MIT,.NET全平台 MIT协议开源了
    DNS泛域名解析应用(nip.io/sslip.io)
    对象池在 .NET (Core)中的应用[3]: 扩展篇
    对象池在 .NET (Core)中的应用[2]: 设计篇
    对象池在 .NET (Core)中的应用[1]: 编程篇
    项目组织结构的3种类型:职能型、项目型和矩阵型
    [LeetCode] 1208. Get Equal Substrings Within Budget 尽可能使字符串相等
  • 原文地址:https://www.cnblogs.com/domi22/p/8047844.html
Copyright © 2020-2023  润新知