mybatis常用搜索条件总结

  • Post author:
  • Post category:其他


所有的都需要放在这里面
<where>
</where>
等于示例
<if test=" XXXX != null and XXXX != '' ">
	and XXXX = #{XXXX,jdbcType=VARCHAR}
</if>

like模糊查询示例
<if test=" DRINKWATER_NAME != null and DRINKWATER_NAME != '' ">
	<bind name="DRINKWATER_NAME" value="'%'+ DRINKWATER_NAME + '%'" />
	AND DRINKWATER_NAME LIKE #{DRINKWATER_NAME,jdbcType=VARCHAR}
</if>

时间示例
<if test=" START_TIME != null and START_TIME != '' ">
	AND START_TIME >= #{START_TIME,jdbcType=VARCHAR}
</if>
<if test=" END_TIME != null and END_TIME != '' ">
	AND END_TIME >= #{END_TIME,jdbcType=VARCHAR}
</if>

时间转换示例
CONVERT(varchar(100), A.MONITOR_TIME,120)

循环示例
<if test=" CODE_CONTROLLEVEL != null and CODE_CONTROLLEVEL != '' ">
	AND CODE_CONTROLLEVEL IN
	<foreach collection="CODE_CONTROLLEVEL.split(',')" open="(" item="CODE_CONTROLLEVEL" separator=","
			 close=")">
		#{CODE_CONTROLLEVEL,jdbcType=VARCHAR}
	</foreach>
</if>



版权声明:本文为changyj159635原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。