mybaits where标签的使用和写法

<!-- 统计侧坡数据记录 -->
	<select id="count" parameterType="com.XinjueManager.common.InquiryCondition" resultType="int">
	
		SELECT count(*) from sys_evaluatio_data
		<where>
		<if test="cndtn1 !=null and cndtn1 !='' "> 
			platform = #{cndtn1}
	   	</if>
	   	<if test="cndtn2 !=null and cndtn2 !='' "> 
			and province = #{cndtn2}
	   	</if>
	   	<if test="cndtn3 !=null and cndtn3 !='' "> 
			and evaluationId = #{cndtn3}
	   	</if>
	   	<if test="cndtn4 !=null and cndtn4 !='' "> 
			and formNumber LIKE CONCAT("%",#{cndtn4},"%")
	   	</if>
	   	<if test="cndtn5 !=null and cndtn5 !='' "> 
			and city = #{cndtn5}
	   	</if>
		</where>
	    	
	</select>

在上面的 where标签中的判断语句  如何在第二个判断语句不加上 and的话 查询如果是需要多个条件 就会报错

where 元素知道只有在一个以上的if条件有值的情况下才去插入“WHERE”子句。而且,若最后的内容是“AND”或“OR”开头的,where 元素也知道如何将他们去除。

发布了72 篇原创文章 · 获赞 3 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/tanqingfu1/article/details/103504885