mybatis 查詢sql時foreach使用法

2022-02-20 23:08:23 字數 497 閱讀 8670

找到倆個例子摘下來

sql查詢使用者in傳list引數

select * from tb1_emplyee where id in

#批量插入

insert into tb1_emplyee(last_name,email,gender,d_id)

values

(#,#,#,#)

collection:指定要遍歷的集合:

list型別的引數會特殊處理封裝在map中,map的key就叫list

item:將當前遍歷出的元素賦值給指定的變數

separator:每個元素之間的分隔符

open:遍歷出所有結果拼接乙個開始的字元

close:遍歷出所有結果拼接乙個結束的字元

index:索引。遍歷list的時候是index就是索引,item就是當前值

遍歷map的時候index表示的就是map的key,item就是map的值

#就能取出變數的值也就是當前遍歷出的元素

MyBatis動態sql查詢

什麼是動態sql mybatis核心 對sql語句進行靈活操作,通過表示式進行判斷,對sql進行靈活拼接 組裝。需求public class userpo if test userpo.id null and id if if where select id findusercount parame...

使用mybatis時防止sql注入

size large b 一.where條件 like 注入 b 錯誤 示例 select id,name from user where name like 注入方式1 在文字框直接把name對應的值寫為 那後端sql直接變為select id,name from user where name ...

mybatis 動態sql(查詢學習)

mybatis 這個框架 與書寫 sql 語句 有很大的關係,所以 在 沒有 sql 很好的 書寫能力下,會遇到好多問題,本人就是例子,先將學習 查詢操作中遇到的問題進行總結 一,標籤的使用,繫結上下文 多用與 sql 語句中 sql 語句like 模糊查詢使用 使用案列 select from s...