1. 程式人生 > 其它 >根據條件查詢 查詢語句條件引數一定要判空

根據條件查詢 查詢語句條件引數一定要判空


//根據條件查詢 查詢語句條件引數一定要判空,判斷null空和字串空 不判空會出現奇怪的問題,查出來的不是根據條件查到的結果


<select id="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>
<select 
id="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>