zoukankan      html  css  js  c++  java
  • 配置generatorConfig.xml自动生成的代码的sql书写问题

     1 <?xml version="1.0" encoding="UTF-8" ?>  
     2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >  
     3 <generatorConfiguration>  
     4     <!-- 引入配置文件 -->  
     5     <properties resource="init.properties"/>  
     6       
     7     <!-- 指定数据连接驱动jar地址 -->  
     8     <classPathEntry location="${classPath}" />  
     9       
    10     <!-- 一个数据库一个context -->  
    11     <context id="infoGuardian">  
    12         <!-- 注释 -->  
    13         <commentGenerator >  
    14             <property name="suppressAllComments" value="false"/><!-- 是否取消注释 -->  
    15             <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->  
    16         </commentGenerator>  
    17           
    18         <!-- jdbc连接 -->  
    19         <jdbcConnection driverClass="${jdbc_driver}"  
    20             connectionURL="${jdbc_url}" userId="${jdbc_user}"  
    21             password="${jdbc_password}" />  
    22           
    23         <!-- 类型转换 -->  
    24         <javaTypeResolver>  
    25             <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->  
    26             <property name="forceBigDecimals" value="false"/>  
    27         </javaTypeResolver>  
    28           
    29         <!-- 生成实体类地址 -->    
    30         <javaModelGenerator targetPackage="com.oop.eksp.user.model"  
    31             targetProject="${project}" >  
    32             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
    33             <property name="enableSubPackages" value="false"/>  
    34             <!-- 是否针对string类型的字段在set的时候进行trim调用 -->  
    35             <property name="trimStrings" value="true"/>  
    36         </javaModelGenerator>  
    37           
    38         <!-- 生成mapxml文件 -->  
    39         <sqlMapGenerator targetPackage="com.oop.eksp.user.data"  
    40             targetProject="${project}" >  
    41             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
    42             <property name="enableSubPackages" value="false" />  
    43         </sqlMapGenerator>  
    44           
    45         <!-- 生成mapxml对应client,也就是接口dao -->      
    46         <javaClientGenerator targetPackage="com.oop.eksp.user.data"  
    47             targetProject="${project}" type="XMLMAPPER" >  
    48             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
    49             <property name="enableSubPackages" value="false" />  
    50         </javaClientGenerator>  
    51           
    52         <!-- 配置表信息 -->      
    53         <table schema="${jdbc_user}" tableName="s_user"  
    54             domainObjectName="UserEntity" enableCountByExample="false"  
    55             enableDeleteByExample="false" enableSelectByExample="false"  
    56             enableUpdateByExample="false">  
    57             <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
    58                 是否生成 example类   -->  
    59               
    60             <!-- 忽略列,不生成bean 字段 -->  
    61             <ignoreColumn column="FRED" />  
    62             <!-- 指定列的java数据类型 -->  
    63             <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />  
    64         </table>  
    65   
    66     </context>  
    67 </generatorConfiguration>

    自动生成Mappler.xml 和dao接口。基本的查询都有,需要一些拼接

    例如:

     1  <select id = "selectShopCartByCustomerId" parameterType="com.hebg3.mobiledealer.modules.storeorder.entity.ShopCartExample" resultMap="BaseResultMap">
     2       select
     3         <if test="distinct">
     4             distinct
     5         </if>
     6         <include refid="Base_Column_List" />
     7         from t_shop_cart
     8         <if test="_parameter != null">
     9             <include refid="Example_Where_Clause" />
    10         </if>
    11         <if test="orderByClause != null">
    12             order by ${orderByClause}
    13         </if>
    14   
    15   
    16   </select>
    1 ShopCartExample shopCartExample = new ShopCartExample();
    2         
    3         shopCartExample.or().andTCustomerIdEqualTo(tCustomerId);
    4         shopCartExample.setOrderByClause("t_dealer_id,create_date ");
    1 ShopCartExample shopCartExample = new ShopCartExample();
    2         
    3         shopCartExample.or().andTCustomerIdEqualTo(tCustomerId);
    4         shopCartExample.setOrderByClause("t_dealer_id,create_date ");
  • 相关阅读:
    Consul负载均衡策略记录
    ASP NET CORE开发优化相关专用随笔
    .NET CORE 3.1配置文件读取方式
    CentOS 8 安装.NET CORE 3.1 发布以及运行
    CORE EF生成ORACLE数据库模型报错问题记录
    【转载】一名程序员十年技术之路的思考与感悟
    iview-admin部署linux nginx报500错误的问题记录
    [转]浅谈账号系统设计
    C#使用phantomjs,爬取AJAX加载完成之后的页面
    nginx触屏版跟PC的代理设置
  • 原文地址:https://www.cnblogs.com/fengchaoLove/p/5790352.html
Copyright © 2011-2022 走看看