1.當查詢條件為空時,查詢所有數據;當查詢條件不為空時,根據條件查詢。
語句1:select * from mainInfo where 1=1 ${if(len(mainInfoId) == 0,"","and mainInfoId = '" + mainInfoId + "'")}
語句2: select * from mainInfo where 1=1 ${if(len(mainInfoId) == 0,nofilter,"and mainInfoId = '" + mainInfoId + "'")}
在 ${if(len(mainInfoId)>0,nofilter,"1=1")} 中,nofilter 表示參數 mainInfoId 為空,就不過濾;若不為空則以參數值進行過濾。
語句1與語句2 查詢結果一致,2個sql都可以使用。