mybatis模糊查詢實現

2021-07-30 07:32:20 字數 436 閱讀 7071

最近在用mybatis做模糊查詢的時候,這個『%xx%』不知道怎麼插入,直接寫在sql語句裡面沒法實現,在網上查了一下主要有兩種比較好的方式實現

1.使用標籤

select * from table where field like #

注意:_paramter代指傳入的引數,如果引數型別是基本資料型別或者它們對於的類型別,就直接寫_paramter,如果是包裝型別,寫為_paramter.getter()       getter()代指對應欄位的get方法

2.使用concat

sql語句寫為 select * from table where field like concat('%','$','%')

或 select * from table where field like

concat

('%',#,'%')

Mybatis實現模糊查詢

mybatis實現模糊查詢 2020.11.5 我知道sql語句是下面的寫法 select id name from client where name like 趙 一開始我在mybatis.xml中寫的查詢語句是這樣的 下面是查詢客戶表中含有趙字的客戶的語句 select id name fro...

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裡的內容 ...