mybatis-plus 2.x 到 3.x 有以下改進
- 分頁查詢可以直接返回
Ipage<T>
的子類(下面會有詳細使用說明) Wrapper<T>
實現類的改動1.
EntityWrapper<T>
更名為QueryWrapper<T>
2.新增一個實現類UpdateWrapper<T>
用於update
方法BaseMapper<T>
的改動1.去除了
insertAllColumn(T entity)
方法
2.去除了updateAllColumn(T entity)
方法
3.新增update(T entity, Wrapper<T> updateWrapper)
方法
Wrapper<T>
使用
QueryWrapper<T>
與UpdateWrapper<T>
共有方法
方法名 | 說明 |
---|---|
allEq | 基於 map 內容等於= |
eq | 等於 = |
ne | 不等於 <> |
gt | 大於 > |
ge | 大於等於 >= |
lt | 小於 < |
le | 小於等於 <= |
between | BETWEEN 條件語句 |
notBetween | NOT BETWEEN 條件語句 |
like | LIKE '%值%'' |
notLike | NOT LIKE '%值%' |
likeLeft | LIKE '%值' |
likeRight | LIKE '值%' |
-------- | -------- |
isNull | NULL 值查詢 |
isNotNull | NOT NULL 值查詢 |
in | IN 查詢 |
notIn | NOT IN 查詢 |
inSql | IN 查詢(sql注入式) |
notInSql | NOT IN 查詢(sql注入式) |
groupBy | 分組 GROUP BY |
orderByAsc | ASC 排序 ORDER BY |
orderByDesc | DESC 排序 ORDER BY |
orderBy | 排序 ORDER BY |
having | HAVING 關鍵詞(sql注入式) |
-------- | -------- |
or | or 拼接 |
apply | 拼接自定義內容(sql注入式) |
last | 拼接在最后(sql注入式) |
exists | EXISTS 條件語句(sql注入式) |
notExists | NOT EXISTS 條件語句(sql注入式) |
-------- | -------- |
and(Function) | AND (嵌套內容) |
or(Function) | OR (嵌套內容) |
nested(Function) | (嵌套內容) |
QueryWrapper<T>
特有方法
方法名 | 說明 |
---|---|
select | SQL 查詢字段內容,例如:id,name,age(重復設置以最后一次為准) |
UpdateWrapper<T>
特有方法
方法名 | 說明 |
---|---|
set | SQL SET 字段(一個字段使用一次) |
分頁查詢
IPage<T> selectPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper);
以上面的方法為例,入參一個
IPage<T>
接口的子類(可以使用mp自帶的一個叫Page<T>
的子類), 返回一個IPage<T>
,其實這個返回的分頁類==入參的分頁類
, 如果你需要自定義一個分頁方法只需要注意一點:入參第一位放置你使用的IPage<T>
子類!
update(T entity, Wrapper<T> updateWrapper)
使用
只需要注意,入參第一位是需要update的實體類,
updateWrapper
里的實體類是用於生成where條件的