ql配置中好比in(#rewr#) 與in ($rewr$)在Ibatis中咱們使用SqlMap進行Sql查詢時須要引用參數,在參數引用中遇到的符號#和$之間的區分爲,#能夠進行與編譯,進行類型匹配,而$不進行數據類型匹配,例如:
select * from table where id = #id# ,其中若是字段id爲字符型,那麼#id#表示的就是'id'類型,若是id爲整型,那麼#id#就是id類型。
select * from table where id = $id$ ,若是字段id爲整型,Sql語句就不會出錯,可是若是字段id爲字符型,那麼Sql語句應該寫成 select * from table where id = '$id$'
$ 的做用其實是字符串拼接,
select * from $tableName$
等效於
StringBuffer sb = new StringBuffer(256);
sb.append("select * from ").append(tableName);
sb.toString();
#用於變量替換 select * from table where id = #id# 等效於 prepareStement = stmt.createPrepareStement("select * from table where id = ?") prepareStement.setString(1,'abc'); ------------------------------------------------ 說道這裏, 總結一下, 何時用$,何時 用 # 對於變量部分, 應當使用#, 這樣能夠有效的防止sql注入, 將來,# 都是用到了prepareStement,這樣對效率也有必定的提高 $只是簡單的字符拼接而已,對於非變量部分, 那隻能使用$, 實際上, 在不少場合,$也是有不少實際意義的 例如 select * from $tableName$ 對於不一樣的表執行統一的查詢 update $tableName$ set status = #status# 每一個實體一張表,改變不用實體的狀態 特別提醒一下, $只是字符串拼接, 因此要特別當心sql注入問題。