Mybatis實現模糊查詢

2021-10-10 11:03:57 字數 920 閱讀 5469

mybatis實現模糊查詢(2020.11.5)

我知道sql語句是下面的寫法

select

`id`

,`name`

from

`client`

where

`name`

like

'%趙%'

;

一開始我在mybatis.xml中寫的查詢語句是這樣的

下面是查詢客戶表中含有趙字的客戶的語句

select

`id`

,`name`

from

`client`

<

where

>

<

if test=

"name != null and name != ''"

>

`name`

like

'%'#'%';

>

<

/where

>

但是這樣查詢不出來

就在網上搜尋,說是要用concat函式,用來把%和搜尋的關鍵字連線起來

於是就把查詢語句換成下面的寫法,查詢的結果就正確了

select

`id`

,`name`

from

`client`

<

where

>

<

if test=

"name != null and name != ''"

>

`name`

like concat(

'%',

#,'%')

>

<

/where

>

mybatis模糊查詢實現

最近在用mybatis做模糊查詢的時候,這個 xx 不知道怎麼插入,直接寫在sql語句裡面沒法實現,在網上查了一下主要有兩種比較好的方式實現 1.使用標籤 select from table where field like 注意 paramter代指傳入的引數,如果引數型別是基本資料型別或者它們對...

Mybatis 模糊查詢

mybatis從入門到精通 書籍筆記 1 使用concat 字串連線函式and user name like concat and user name like concat concat mysql中concat函式可以連線多個引數,oracle中只支援2個引數,所以有些要用多個concat 函式...

mybatis 配置 模糊查詢

使用mybatis連線mysql的話,需要如下步驟 1 生成實體類。public class user implements serializable2 生成主配置檔案,放在resources下面 主配置檔案也可以這樣寫,將連線資料庫的 放到外面 jdbcconfig.properties裡的內容 ...