首页 > 代码库 > ibatis dynamic标签 的使用

ibatis dynamic标签 的使用

<!-- 根据给定的参数查询出对应的对账日志记录 -->    <select id="listByParamMap" parameterClass="java.util.Map" resultClass="AccCheckLog">        select rl.ID as id,               rl.STAFF_ID as staffId,               rl.STAFF_NAME as staffName,               rl.STAFF_PHONE_NUM as staffPhoneNum,               rl.ORDER_ID as orderId,               rl.AWARD_DATE as awardDate,               rl.PAY_AMOUNT as payAmount,               rl.ISSUER_ID as issuerId,               rl.APPFROM as appfrom,               rl.ISSUER_NAME as issuerName,               rl.LOG_TIME as logTime,               rl.TYPE as type,               rl.COMMENTS as comments,               rl.CHECK_RESULT_CODE as checkResultCode          from INFO_AWARD_COUPON_RECORD_LOG rl          <dynamic prepend="where">                <isNotNull property="appfrom" prepend="and">                        rl.APPFROM = #appfrom#                </isNotNull>                <isNotNull property="staffId" prepend="and">                        rl.STAFF_ID = #staffId#                </isNotNull>                <isNotNull property="orderId" prepend="and">                        rl.ORDER_ID = #orderId#                </isNotNull>                <isNotNull property="logTimeStart" prepend="and">                        <![CDATA[rl.LOG_TIME >= to_date(#logTimeStart#,‘yyyymmdd‘)]]>                </isNotNull>                <isNotNull property="logTimeEnd" prepend="and">                        <![CDATA[rl.LOG_TIME <= to_date(#logTimeEnd#,‘yyyymmdd‘)]]>                </isNotNull>                <isNotNull property="checkResultCode" prepend="and">                        rl.CHECK_RESULT_CODE = #checkResultCode#                </isNotNull>                <isNotNull property="checkResultCodeNEq1" prepend="and">                        rl.CHECK_RESULT_CODE != #checkResultCodeNEq1#                </isNotNull>          </dynamic>    </select>

dynamic的prepend只要检测到第一个为“真”的条件比较元素(isNotNull标签),则覆盖其prepend属性并组装where关键字为动态SQL的一部分.

 

ibatis dynamic标签 的使用