Mybatis中 和 的區別

2021-10-01 09:41:16 字數 425 閱讀 7828

#{}在sql中顯示是?標識佔位符是以預編譯的形式,將引數設定到sql語句中;preparedstatement,防止sql注入

例如:

select * from user where id = ?

${}在sql中顯示的是獲取的值;會直接拼裝在sql中,會有安全問題。

select * from user where id = 1
原生jdbc不支援佔位符的地方可以使用${}進行取值,比如分表,排序;按照年份進行分表拆分。

select * from $_salary where ***;

select * from user 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...