1、mybatisplus——入門(一)
2、mybatisplus——準備(二)
3、mybatisplus——crud(三)
4、mybatisplus——條件查詢構造器(四)
@runwith
(springrunner.
class
)@springboottest
public
class
注意:以下條件構造器的方法入參中的 column 均表示資料庫字段
1、ge、gt、le、lt、isnull、isnotnull
@test
public
void
testdelete()
sql:update user set deleted=1 where deleted=0 and name is null and age >= ? and email is not null
2、eq、ne
注意:seletone返回的是一條實體記錄,當出現多條時會報錯
@test
public
void
testselectone()
select id,name,age,email,create_time,update_time,deleted,version from user where deleted=0 and name = ?
3、between、notbetween
@test
public
void
testselectcount()
select count(1) from user where deleted=0 and age between ? and ?
4、alleq
@test
public
void
testselectlist()
select id,name,age,email,create_time,update_time,deleted,version from user where deleted=0 and name = ? and id = ? and age = ?
5、like、notlike、likeleft、likeright
selectmaps返回map集合列表
@test
public
void
testselectmaps()
select id,name,age,email,create_time,update_time,deleted,version from user where deleted=0 and name not like ? and email like ?
6、in、notin、insql、notinsql、exists、notexists
in、notin:
insql、notinsql:可以實現子查詢
@test
public
void
testselectobjs()
select id,name,age,email,create_time,update_time,deleted,version from user where deleted=0 and id in (select id from user where id < 3)
7、or、and
不呼叫or則預設為使用 and 連
@test
public
void
testupdate1()
update user set name=?, age=?, update_time=? where deleted=0 and name like ? or age between ? and ?
8、巢狀or、巢狀and
這裡使用了lambda表示式,or中的表示式最後翻譯成sql時會被加上圓括號
@test
public
void
testupdate2()
update user set name=?, age=?, update_time=?
where deleted=0 and name like ?
or ( name = ? and age <> ? )
9、orderby、orderbydesc、orderbyasc
@test
public
void
testselectlistorderby()
select id,name,age,email,create_time,update_time,deleted,version
from user where deleted=0 order by id desc
10、last
直接拼接到 sql 的最後
注意:只能呼叫一次,多次呼叫以最後一次為準 有sql注入的風險,請謹慎使用
@test
public
void
testselectlistlast()
select id,name,age,email,create_time,update_time,deleted,version
from user where deleted=0
limit 1
11、指定要查詢的列
@test
public
void
testselectlistcolumn()
select id,name,age from user where deleted=0
12、set、setsql
@test
public
void
testupdateset()
update user setage=?,update_time=?,name=?, email = 『[email protected]』 where deleted=0 and name like ? Mybatis plus實現條件查詢
教程目錄 教程一 mybatis plus使用教程 教程二 mybatis plus的字段自動填充 教程三 mybatis實現物理刪除和邏輯刪除 教程四 mybatis plus實現樂觀鎖 教程五 mybatis plus實現條件查詢 條件查詢 複雜查詢 test public void tests...
mybatis plus 多表條件分頁查詢
今天寫mybatis plus 多表條件分頁查詢的時候碰到很多問題,這裡記錄下 首先說下業務,這個是要展現的頁面。根據篩選的條件對資料進行分頁查詢。setter getter noargsconstructor allargsconstructor public class pagedweeklyd...
MybatisPlus多條件查詢並分頁
輸入任意字段進行查詢,如果欄位為空,則忽略該欄位,並分頁輸出。public result findmulti string name,string string position,string phone,integer department id,integer now page,integer ...