zoukankan      html  css  js  c++  java
  • ibatis.net学习笔记(五) 带条件查询语法

    这里拿一个新闻表来做介绍

      <resultMaps>
        <resultMap id="FullResultMap" class="News">
            <result property="NewsID" column="NewsID" type="System.Int32" dbType="SqlDbType.Int"/>
            <result property="CateID" column="CateID" type="System.Int32" dbType="SqlDbType.Int"/>
            <result property="Title" column="Title" type="System.String" dbType="SqlDbType.NVarChar"/>
            <result property="Summary" column="Summary" type="System.String" dbType="SqlDbType.NVarChar"/>
            <result property="Description" column="Description" type="System.String" dbType="SqlDbType.NText"/>
            <result property="IsTop" column="IsTop" type="System.Boolean" dbType="SqlDbType.Bit"/>
            <result property="IsShow" column="IsShow" type="System.Boolean" dbType="SqlDbType.Bit"/>
            <result property="Visitation" column="Visitation" type="System.Int32" dbType="SqlDbType.Int"/>
            <result property="PublishTime" column="PublishTime" type="System.DateTime" dbType="SqlDbType.DateTime"/>
            <result property="UpdateTime" column="UpdateTime" type="System.DateTime" dbType="SqlDbType.DateTime"/>
            <result property="CreateUser" column="CreateUser" type="System.Int32" dbType="SqlDbType.Int"/>
            <result property="UpdateUser" column="UpdateUser" type="System.Int32" dbType="SqlDbType.Int"/>
        </resultMap>
      </resultMaps>

    1  如果 CateID >0 执行查询 select * from news where CateID=xxx

       <select id="SelectAllRecord"  parameterClass="Hashtable" resultClass="int">
          SELECT count(*) from News
          <dynamic prepend="where"> --条件成立时前面要加的字符串 prepend ="字符串" 如果下面条件成立 追加where
            <isGreaterThan    property="CateID"  compareValue="0">  -- 如果是属性关键字是比较条件时,字符串存放要比较的值compareValue="字符串"   如果>0 追加  CateID = #CateID#
              CateID = #CateID#
            </isGreaterThan>
          </dynamic>
        </select>

    其他参数列表

    <isEqual>

    如果参数相等于值则查询条件有效。

    <isNotEqual>

    如果参数不等于值则查询条件有效。

    <isGreaterThan>

    如果参数大于值则查询条件有效。

    <isGreaterEqual>

    如果参数等于值则查询条件有效。

    <isLessEqual>

    如果参数小于值则查询条件有效。如下所示:

    <isLessEqual prepend = ”AND” property = ”Visitation” compareValue = ”18” >

    IsShow= ‘TRUE’

    </isLessEqual>

    <isPropertyAvailable>

    如果参数有使用则查询条件有效。

    <isNotPropertyAvailable>

    如果参数没有使用则查询条件有效。

    <isNull>

    如果参数为NULL则查询条件有效。

    <isNotNull>

    如果参数不为NULL则查询条件有效。

    <isEmpty>

    如果参数为空则查询条件有效。

    <isNotEmpty>

    如果参数不为空则查询条件有效。参数的数据类型为Collection、String 时参数不为NULL或“”。如下所示:

    <isNotEmpty prepend=”AND” property=”Visitation” >  select * from news where xxxx and  Visitation=#Visitation#

        Visitation=#Visitation#

    </isNotEmpty>

    <isParameterPresent>

    如果参数类不为NULL则查询条件有效。

    <isNotParameterPresent>

    <isNotParameterPresent prepend=”AND”>

        EMPLOYEE_TYPE = ‘DEFAULT’

    </isNotParameterPresent>

  • 相关阅读:
    腾讯优测优分享 | Android适配中的一些特殊情况小结
    腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
    腾讯优测优分享 | 让你头疼的手机应用自动遍历可以这样实现
    腾讯优测优分享 | 适配路上,避免掉入“扫码调用相机”的坑
    腾讯优测优分享 | 游戏的UI自动化测试可以这样开展
    腾讯优测优分享 | 这样做测试用例评审更高效
    腾讯优测优分享 | Android性能测试工具化实现
    腾讯优测优分享 | 分布式系统测试的应用方法——场景注入测试
    腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
    腾讯优测优分享 | 谈谈移动端屏幕适配的几种方法
  • 原文地址:https://www.cnblogs.com/jcgh/p/2628457.html
Copyright © 2011-2022 走看看