mybatis-plus 從2.x到3.x升級指南

mybatis-plus 2.x 到 3.x 有如下改進

  • 分頁查詢能夠直接返回Ipage<T>的子類(下面會有詳細使用說明)
  • Wrapper<T>實現類的改動

    1.EntityWrapper<T>改名爲QueryWrapper<T>
    2.新增一個實現類UpdateWrapper<T>用於update方法git

  • BaseMapper<T>的改動

    1.去除了insertAllColumn(T entity)方法
    2.去除了updateAllColumn(T entity)方法
    3.新增update(T entity, Wrapper<T> updateWrapper)方法github

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>子類!sql

update(T entity, Wrapper<T> updateWrapper)使用

只須要注意,入參第一位是須要update的實體類,updateWrapper裏的實體類是用於生成where條件的mybatis

原文 https://github.com/baomidou/mybatis-plus-doc/blob/mp3/update-3.x.md#%E4%BB%8E2x%E5%88%B03x%E5%8D%87%E7%BA%A7%E6%8C%87%E5%8D%97app

官方文檔:http://mp.baomidou.comspa

相關文章
相關標籤/搜索