根據條件查詢 查詢語句條件引數一定要判空
阿新 • • 發佈:2022-01-11
//根據條件查詢 查詢語句條件引數一定要判空,判斷null空和字串空 不判空會出現奇怪的問題,查出來的不是根據條件查到的結果
<select id="list" resultMap="typeResultMap" > select * from type <where> <!--id--> <if test="id!=null and id!=''"> and id like '%${id}%' </if> <!--ISBN--> <iftest="name!=null and name!=''"> and name like '%${name}%' </if> <!--書名--> <if test="remake!=null and remake!=''"> and remake like '%${remake}%' </if> </where> </select>
<selectid="list" resultMap="typeResultMap" >
select * from type
<where>
<!--id-->
<if test="id!=null and id!=''">
and id like '%${id}%'
</if>
<!--ISBN-->
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
<!--書名-->
<if test="remake!=null and remake!=''">
and remake like '%${remake}%'
</if>
</where>
</select>