MyBatis plus 查詢 模糊查詢的使用

2021-10-20 16:08:09 字數 1436 閱讀 7687

在使用mybatis-plus的時候,一些基礎的增刪改查可以不用再自己寫sql了:}

就這樣,就可以實現user表的增刪改查了。

模糊查詢

如果需要模糊查詢,**如下:

//條件封裝
這裡,like方法有三個引數:

需要說明的是,這裡的like查詢是使用的預設方式,也就是說在查詢條件的左右兩邊都有%:name = 『%王%";

如果只需要在左邊或者右邊拼接%,可以使用likeleft或者likeright方法。

其他示例

模糊查詢方法一

controller

//模糊查詢方法一

public responseobj> testtask(@requestparam("name") string name)

userinfo是需要模糊查詢的表對應的model,firstname和lastname則是需要模糊查詢的字段,or()是指兩個條件或者的關係,在sql中執行的語句是:

select * from users where (firstname like "%海%" or lastname like "%海%")
這裡selectlist方法是mybatis-plus中的

模糊查詢方法二

這個是通過傳入物件進行模糊查詢

//模糊查詢方法二

public responseobj> testtask1(@modelattribute userinfo userinfo)

}system.out.println(listall.size());

// 按userid公升序、username降序、birthdate公升序排序

string sortnamearr = ;

boolean isascarr = ;

listutils.sort(listall, sortnamearr, isascarr);

system.out.println("

--------按按userid公升序、username降序、birthdate公升序排序(如果userid相同,則按照username降序," +

"如果username相同,則按照birthdate公升序)------------------");

return new responseobj<>(listall, null);

}

select

*from

users

where

1=1and concat(lastname, firstname) like concat("%",#,"%")

$

mybatis plus模糊查詢

模糊查詢方法一 control 模糊查詢方法一 public responseobj testtask requestparam name string name userinfo是需要模糊查詢的表對應的model,firstname和lastname則是需要模糊查詢的字段,or 是指兩個條件或者的...

MyBatis plus 模糊查詢的使用

在使用mybatis plus的時候,一些基礎的增刪改查可以不用再自己寫sql了 public inte ce userdao extends basemapper 就這樣,就可以實現user表的增刪改查了。模糊查詢 使用userdao.selectlist querywrapper 方法,就可以查...

mybatis plus 聯合查詢

在xml中只需要需要寫如下的 即可實現分頁 select from user where name like concat 呼叫方法 分頁外掛程式 public static void testpagelistuser 貢獻一波自己的 1 呼叫 pagepage new page current,l...