IF語句學習
第一種寫法(標準)
我們先來看以下標準寫法:
select * from ..
<where>
? ? ? ? <if test="">
? ? ? ? ? ? ? ? and .......
????????<if test="">
? ? ? ? ? ? ? ? and .......
<where>
?我們用了一個where標簽 , 內嵌if語句
第二種寫法:
這是第二種寫法:不用where標簽,直接用<if>標簽跟在where語句后(這種其實沒任何問題, 如果你也看where不順眼,就用第一種寫法)
企業開發 :
if語句用于分頁查詢的例子如下:
<select id="pageQuery" resultType="com.sky.entity.Employee">select * from employee<where><if test="name!=null and name!=''">and name like concat('%',#{name},'%')</if></where>order by create_time desc</select>
這里用于分頁查詢 ,? 用了一個concat語句 :??concat('%',#{name},'%')
可以實現關鍵字查詢(多用于搜索功能模塊開發)