}注意:以下條件構造器的方法入參中的column
均表示資料庫字段
@testsql:update user set deleted=1 where deleted=0 and name is null and age >= ? and email is not nullpublic
void
testdelete()
注意:seletone返回的是一條實體記錄,當出現多條時會報錯
@testselect id,name,age,email,create_time,update_time,deleted,version from user where deleted=0 and name = ?public
void
testselectone()
包含大小邊界
@testselect count(1) from user where deleted=0 and age between ? and ?public
void
testselectcount()
@testselect id,name,age,email,create_time,update_time,deleted,versionpublic
void
testselectlist()
from user where deleted=0 and name = ? and id = ? and age = ?
selectmaps返回map集合列表
@testselect id,name,age,email,create_time,update_time,deleted,versionpublic
void
testselectmaps()
from user where deleted=0 and name not like ? and email like ?
in、notin:
insql、notinsql:可以實現子查詢
@testselect id,name,age,email,create_time,update_time,deleted,versionpublic
void
testselectobjs()
from user where deleted=0 and id in (select id from user where id < 3)
注意:
不呼叫or
則預設為使用and
連
@testupdate user set name=?, age=?, update_time=? where deleted=0 and name like ? or age between ? and ?public
void
testupdate1()
這裡使用了lambda表示式,or中的表示式最後翻譯成sql時會被加上圓括號
@testupdate user set name=?, age=?, update_time=?public
void
testupdate2()
where deleted=0 and name like ?
or ( name = ? and age <> ? )
@testselect id,name,age,email,create_time,update_time,deleted,versionpublic
void
testselectlistorderby()
from user where deleted=0 order by id desc
直接拼接到 sql 的最後
注意:只能呼叫一次,多次呼叫以最後一次為準 有sql注入的風險,請謹慎使用
@testselect id,name,age,email,create_time,update_time,deleted,versionpublic
void
testselectlistlast()
from user where deleted=0 limit 1
@testselect id,name,age from user where deleted=0public
void
testselectlistcolumn()
@testupdate user set age=?, update_time=?, name=?, email = '[email protected]' where deleted=0 and name like ?public
void
testupdateset()
04 MyBatisPlus條件構造器
runwith springrunner.class springboottest public class 注意 以下條件構造器的方法入參中的column均表示資料庫字段 test public void testdelete sql update user set deleted 1 where...
Mybatis plus實現條件查詢
教程目錄 教程一 mybatis plus使用教程 教程二 mybatis plus的字段自動填充 教程三 mybatis實現物理刪除和邏輯刪除 教程四 mybatis plus實現樂觀鎖 教程五 mybatis plus實現條件查詢 條件查詢 複雜查詢 test public void tests...
MybatisPlus條件構造器Wrapper
我們寫一些複雜的sql就可以使用它來替代!1 測試一 查詢name不為空的使用者,並且郵箱不為空的使用者,年齡大於等於12 test void contextloads 2 測試二 查詢名字狂神說 bilibili中搜尋,講的很好 test void test2 3 測試三 查詢年齡在 20 30 ...