1. 符號(hào)#和$的區(qū)別
select * from WZGL_Wzdrd where dwbh=#{dwbh,jdbcType=VARCHAR} and dbdbh in ${dbdbh}
符號(hào)#表示會(huì)作為字符串挟冠,自動(dòng)加上引號(hào)犁嗅;符號(hào)$表示會(huì)作為SQL語句的一部分猿棉,不加引號(hào)磨隘。例如上面的例子中我可以通過dbdbh傳入('001','002','003','004','005')
2. 大于號(hào)和小于號(hào)要使用轉(zhuǎn)義字符
大于號(hào)>用>
小于號(hào)<用<
不等于<>用<>
3. 連接字符串
<if test="null != customerName and '' != customerName">
and customer_name like CONCAT('%',#{customerName},'%')
</if>
4. IN 的用法
方法一
<!--根據(jù)多個(gè)ID查找 -->
<select id="queryByDbdbh" resultMap="authorResultMap">
SELECT * FROM WZGL_Wzdrd
WHERE dbdbh in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
<!-- collection:傳入?yún)?shù)的名稱 index:索引: item:collection的別名 -->
</select>
方法二
select * from WZGL_Wzdrd where dwbh=#{dwbh,jdbcType=VARCHAR} and dbdbh in ${dbdbh}
注意#和$的區(qū)別,這里dbdbh提前構(gòu)造為“('001','002','003','004','005')”