mybatis中 和 的區別

2022-07-01 13:57:15 字數 530 閱讀 2231

mybatis是一款優秀的持久層框架。它的強大之一就是sql的動態組裝了。在mybatis中#和$都表示引數的引用,表示乙個佔位符。

1、#號在sql中以字串形式顯示,可以有效防止sql注入攻擊。例如select * from emp where name=#,傳入jason時,實際上sql語句是這樣的:select * from emp where name="jason"。

2、$在sql中以值的形式表示(即原樣顯示),不能防止sql注入攻擊。例如select * from emp where name =$,傳入jason時,sql語句變為select * from emp where name=jason。也就是#在傳入值時會加引號變成字串,而$則不會變為字串而是原樣顯示。

模糊查詢和order by後面的字段時必須使用$,否則報錯。

具體詳細參見:

myBatis中 和 區別

1.將傳入的資料都當成乙個字串,會對自動傳入的資料加乙個雙引號。如 order by user id 如果傳入的值是111,那麼解析成sql時的值為order by 111 如果傳入的值是id,則解析成的sql為order by id 2.將傳入的資料直接顯示生成在sql中。如 order by u...

mybatis 中 和 區別

在使用mybatis 框架時 在xml的配置檔案中,通常是使用 來獲取數值的 如 select from t user inf where id 這時 如果你傳入的值為zhangsan 則會編譯成為 select from t user inf where id zhangsan mybatis 會...

Mybatis 中 和 區別

號與 區別 號表示引數,代表乙個字串。如 select a,b,c from table1 where id value 傳入引數後如 value 1 則可生成 select a,b,c from table1 where id 1 select a,b,c from table1 where ci...