每日技术干货,第一时间送达!
1
<select id="queryBookInfo" parameterType="com.ths.platform.entity.BookInfo" resultType="java.lang.Integer">
select count(id) from t_book t where 1=1
<if test="title !=null and title !='' ">
AND title = #{title}
</if>
<if test="author !=null and author !='' ">
AND author = #{author}
</if>
</select>
2
EXPLAIN SELECT * FROM t_book WHERE title = '且在人间';
EXPLAIN SELECT * FROM t_book WHERE 1=1 AND title = '且在人间';
3
<select id="queryBookInfo" parameterType="com.ths.platform.entity.BookInfo" resultType="java.lang.Integer">
select count(*) from t_book t
<where>
<if test="title !=null and title !='' ">
title = #{title}
</if>
<if test="author !=null and author !='' ">
AND author = #{author}
</if>
</where>
</select>
我们用where标签代替。
【福利】2023 高薪课程,全面来袭(视频+笔记+源码)
往期推荐


