1.时间查询
<if test="cancelNoAssignDateBegin != null and cancelNoAssignDateBegin != ''">
<![CDATA[ AND ORDERD.CANCEL_NO_ASSIGN_DATE >= DATE_FORMAT(#{cancelNoAssignDateBegin},'%Y-%m-%d')]]>
</if>
<if test="cancelNoAssignDateEnd != null and cancelNoAssignDateEnd != ''">
<![CDATA[ AND ORDERD.CANCEL_NO_ASSIGN_DATE < DATE_ADD(DATE_FORMAT(#{cancelNoAssignDateEnd},'%Y-%m-%d'),INTERVAL 1 DAY) ]]>
</if>
2.精确查询
<if test="stockType != null and stockType != ''">
AND ORDERD.STOCK_TYPE = #{stockType}
</if>
3.模糊查询
<if test="oldDriName != null and oldDriName != ''">
AND INSTR(ORDERD.OLD_DRI_NAME,#{oldDriName})
</if>
4.多查询
<if test="isAssign != null and isAssign != ''">
AND ORDERD.IS_ASSIGN IN
<foreach item="isAssigns" collection="isAssign.split(',')" index="index" open="(" separator="," close=")">
#{isAssigns}
</foreach>
</if>
5.数字查询
<if test="otherSubsidyBegin != null and otherSubsidyBegin != ''">
<![CDATA[ AND ORDERD.OTHER_SUBSIDY >= cast(#{otherSubsidyBegin} as decimal(24,6))]]>
</if>
<if test="otherSubsidyEnd != null and otherSubsidyEnd != ''">
<![CDATA[ AND ORDERD.OTHER_SUBSIDY <= cast(#{otherSubsidyEnd} as decimal(24,6)) ]]>
</if>
6.单个模糊查询和多查询
<if test="vin != null and vin != ''">
<choose>
<when test='vin.contains(",") == false'>
AND INSTR(ORDERD.VIN,#{vin})
</when>
<otherwise>
AND ORDERD.VIN IN
<foreach item="vins" collection="vin.split(',')" index="index" open="(" separator="," close=")">
#{vins}
</foreach>
</otherwise>
</choose>
</if>
mybatis篇:使用mybatis时各种查询格式
最新推荐文章于 2024-05-03 12:05:30 发布