1、#可以進(jìn)行預(yù)編譯,進(jìn)行類型匹配,#變量名#? 會(huì)轉(zhuǎn)化為 jdbc的?類型
?? $不進(jìn)行數(shù)據(jù)類型匹配,$變量名$就直接把$name$替換為 name的內(nèi)容
?? 例如:
????select * from tablename where id = #id#,假設(shè)id的值為12,其中如果數(shù)據(jù)庫(kù)字段id為字符型,那么#id#表示的就是'12',如果id為整型,那么#id#就是 12
??? 會(huì)轉(zhuǎn)化為jdbc的select * from tablename where id=?,把?參數(shù)設(shè)置為id的值
????select * from tablename where id = $id$,如果字段id為整型,Sql語(yǔ)句就不會(huì)出錯(cuò),但是如果字段id為字符型,
????那么Sql語(yǔ)句應(yīng)該寫(xiě)成 select * from table where id = '$id$'
????
3、#方式能夠很大程度防止sql注入.
4、$方式無(wú)法方式sql注入.
5、$方式一般用于傳入數(shù)據(jù)庫(kù)對(duì)象.例如傳入表名.
6、所以ibatis用#比$好,一般能用#的就別用$.
另外,使用##可以指定參數(shù)對(duì)應(yīng)數(shù)據(jù)庫(kù)的類型
如:
select * from tablename where id =#id:number#?
在做in,like 操作時(shí)候要特別注意
mysql: select * from user where user_name like concat('%',#name#,'%')oracle: select * from user where user_name like '%'||#name#||'%'sql server: select * from user where user_name like '%'+#name#+'%'