iBatis中的动态查询

如果想深入学习,可以参考 Manning.                  iBATIS.in.Action.Jan.2007               
下面给出几个例子和dtd定义:               
<                  selectid="selectDispatchedKey" parameterClass="KeyAndKeyFlowInfo" resultMap="KeyAndKeyFlowResult">                 
   select distinct                 
    KEY_ID,                 
    USER_ID,                 
    INITIATOR,                 
    INIT_DATE,                 
    INITIATOR_EMAIL,                 
    SGS_KEY.BRANCH_NAME,                 
    APPROVER,                 
    APPROVER_EMAIL,                 
    APPROVE_DATE                 
   from                 
    SGS_KEY,                 
    SGS_KEY_FLOW                 
   where SGS_KEY.APPLY_FLOW_ID=SGS_KEY_FLOW.KEY_FLOW_ID                 
   <                  dynamicprepend="and"                  open="(" close=")">                    
    <                  isNotNullproperty="ki.userId" prepend="and" removeFirstPrepend="false">                 
     USER_ID = #ki.userId#                 
    </                  isNotNull>                 
    <                  isNotNullproperty="kfi.initiator"                  prepend="and">                 
     INITIATOR = #kfi.initiator#                 
    </                  isNotNull>                 
    <                  isNotNullproperty="kfi.initDate"                  prepend="and">                 
     INIT_DATE = #kfi.initDate#                 
    </                  isNotNull>                 
   </                  dynamic>                 
< /select>               
                
<                  updateid="updateKeyFlow" parameterClass="KeyFlowInfo">                 
   update SGS_KEY_FLOW set                 
   <                  dynamic>                 
     KEY_FLOW_ID =#keyFlowId#                 
    <isNotNull property="branchName" prepend=",">                 
     BRANCH_NAME = #branchName#                 
    </isNotNull>                 
    <isNotEqual property="operation" prepend="," compareProperty="operation" compareValue="0">                 
     OPERATION = #operation#                 
    </isNotEqual>                 
    <isNotNull property="initiator" prepend=",">                 
     INITIATOR = #initiator#                 
    </isNotNull>                 
    <isNotNull property="initiatorEmail" prepend=",">                 
     INITIATOR_EMAIL = #initiatorEmail#                 
    </isNotNull>                 
    <isNotNull property="initDate" prepend=",">                 
     INIT_DATE = #initDate#                 
    </isNotNull>                 
    <isNotNull property="approver" prepend=",">                 
     APPROVER = #approver#                 
    </isNotNull>                 
    <isNotNull property="approverEmail" prepend=",">                 
     APPROVER_EMAIL = #approverEmail#                 
    </isNotNull>                 
    <isNotNull property="approveDate" prepend=",">                 
     APPROVE_DATE = #approveDate#                 
    </isNotNull>                 
    <isNotEqual property="keyNum" prepend="," compareProperty="keyNum" compareValue="0">                 
     KEY_NUM = #keyNum#                 
    </isNotEqual>                 
    <isNotNull property="applyReason" prepend=",">                 
     APPLY_REASON = #applyReason#                 
    </isNotNull>                 
    <isNotNull property="rejectReason" prepend=",">                 
     REJECT_REASON = #rejectReason#                 
    </isNotNull>                                         
   </                  dynamic>                 
   where                 
    KEY_FLOW_ID =#keyFlowId#                 
< /update>               
                



属性关键字                                                 
                             含义                     

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

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

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

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

<isLessEqual>                                                 
如果参数小于值则查询条件有效。如下所示:                         
<isLessEqual prepend = ”AND” property = ”age” compareValue = ”18” >                         
ADOLESCENT = ‘TRUE’                         
</isLessEqual>                     

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

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

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

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

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

<isNotEmpty>                                                 
如果参数不为空则查询条件有效                             。参数的数据类型为                            Collection                            、                            String                            时参数不为                            NULL                            或“”。如下所示:                         
<isNotEmpty prepend=”AND” property=”firstName” >                         
FIRST_NAME=#firstName#                         
                            < /isNotEmpty>                     

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

<isNotParameterPresent>                                                 
                             Checks to see if the parameter object is not present (null). Example Usage:                         
                            < isNotParameterPresent prepend=”AND”>                         
EMPLOYEE_TYPE = ‘DEFAULT’                         
</isNotParameterPresent>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值