mybatis中採用模糊匹配得到另一種用法

2021-08-01 18:04:36 字數 1075 閱讀 8695

需求:乙個搜尋框同時對userid和title進行模糊查詢。

and dis_id = #

if>

and category = #

if>

and user_id like concat('%',#,'%' )

if>

and user_type = #

if>

and title like concat('%',#,'%' )

if>

where>

![日誌裡的sql是這樣的](這種方式查詢時,日誌裡的sql如上所示,會導致對2個字段進行and查詢,只有都具有相同關鍵字時才可以被查出來。

*

*

"where" prefixoverrides="and \ or">

and dis_id = #

if>

and category = #

if>

and user_id like concat('%',#,'%' )

if>

and user_type = #

if>

and title like concat('%',#,'%' )

if>

select>

`from question

"where" prefixoverrides="and \ or">

dis_id = #

if>

category = #

if>

user_id like concat('%',#,'%' )

if>

user_type = #

if>

or title like concat('%',#,'%' )

if>

select>

trim標籤中不要條件字段,只在 第乙個以後的字段前加「or」即可。 

好了!

Mybatis 10模糊匹配

需求 查詢student表,表中含有 王 的所有使用者 sql select from student where sname like 王 方式1 直接在引數上拼接萬用字元 test public void getstudentbyname 日誌列印 方法3 bind表示式處理 mybatis提供...

mybatis中LIKE模糊查詢

mybatis中對於使用like來進行模糊查詢的幾種方式 使用 由於 是引數直接注入的,導致這種寫法,大括號裡面不能註明jdbctype,不然會報錯org.mybatis.spring.mybatissystemexception nested exception is org.apache.iba...

Mybatis中的模糊查詢

1.當我們從資料庫中查詢資料時,大批量的資料會存在相同的資料。比如重名的人,當我們使用姓名查詢該姓名的所有資料時,我們需要在mybatis中使用到模糊查詢的概念。在介面中定義函式 模糊查詢 使用name查詢的資料為物件tb7,返回的不止乙個物件使用list public listquerybynam...