Mybatis之動態sql(以及 和 的區別)

2021-10-03 01:42:27 字數 1055 閱讀 1956

#{}是將括號中的變數之前是什麼型別傳過來還是什麼型別,然而 ${} 是將括號中的變數傳過來都是字串型別(不管之前什麼型別)

用於查詢操作的標籤

where標籤類似於where 1= 1的作用

第乙個滿足的if 會自動將 and去掉

select id,user_name username,password,real_name realname,age

from user_info

and user_name like #

and age = $

choose標籤

choose標籤類似於switch標籤,裡面只能有乙個when標籤滿足還可以加上otherwise(預設)標籤設定初始

select id,user_name username,password,real_name realname,age

from user_info

and user_name like #

and age = $

and featured = 1

批量刪除(前面不能傳空,list裡面一定要有資料)
foreach標籤

delete from user_info

where id in

#

修改操作的標籤(set標籤)
set標籤可以自動刪除 「,」 最後乙個if標籤不需要」,「

update user_info

user_name=#,

age=#

where id = #

插入操作(insert)還是之前的方法

insert into sys_user (user_name,passwd) values(#, #)

mybatis學習之動態sql

1 select查詢 簡單的select類似如下 select id findbyid resultmap studentresult parametertype integer select from t student where id select 1 if 常用於各種查詢的條件判斷部分 se...

mybatis動態SQL之if標籤

我們根據實體類的不同取值,使用不同的 sql 語句來進行查詢。比如在 id 如果不為空時可以根據 id 查詢,如果 username 不同空時還要加入使用者名稱作為條件。這種情況在我們的多條件組合查詢中經常會碰到。根據使用者資訊,查詢使用者列表 param user return listfindb...

(七)mybatis學習之動態SQL

mybatis的核心是對sql語句進行靈活的操作,通過表示式進行判斷,對sql進行靈活拼接 組裝。動態sql包括 if choose when,otherwise where set trim foreach sql片段 if標籤比較簡單,這裡記錄一下文件內容的例子,通過看例子,就清楚的知道if是如...