mybatis動態sql foreach的用法

2021-09-22 12:25:36 字數 454 閱讀 7414

foreach標籤主要用於構建in條件,他可以在sql中對集合進行迭代。如下:

delete from user where id in

#我們假如說引數為---- int ids = ----那麼列印之後的sql如下:

delete form user where id in (1,2,3,4,5)

釋義:collection :collection屬性的值有三個分別是list、array、map三種,分別對應的引數型別為:list、陣列、map集合,我在上面傳的引數為陣列,所以值為array

item : 表示在迭代過程中每乙個元素的別名

index :表示在迭代過程中每次迭代到的位置(下標)

open :字首

close :字尾

separator :分隔符,表示迭代時每個元素之間以什麼分隔

我們通常可以將之用到批量刪除、新增等操作中。

mybatis動態查詢

當我們需要查詢companylist 對應company表 但是資料又不僅僅只來自company表時,例如 我們還需要area表的省市區名稱時,可以這樣寫 會更優雅點 ps 個人覺得 1.companymodel 企業entity company對應的model 的定義 企業company表對應的m...

mybatis 動態排序

mybatis動態排序目前知道的方式有兩種 1.通過pagehelper com.github.pagehelper pagehelper 版本5.1.4 stringbuffer orderby new stringbuffer 欄位名稱 排序方式 pagehelper.startpage vo....

mybatis動態標籤

動態條件判斷 select from user where 1 1 and username 動態where select from user username 動態遍歷 select from user where id in 其中 標籤 類似於switch,按順序判斷 when 中的條件出否成立...