久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Mybatis 實現一個搜索框對多個字段進行模糊查詢

瀏覽:4日期:2023-10-20 10:53:21
1、問題描述:

最近項目需要提供一個搜索框對多個字段進行模糊查詢的操作代替下拉列表選擇單個字段條件進行模糊查詢的操作。

2、解決辦法:

之前的四個條件的模糊查詢代碼

<if test='featureCode != null'> AND plm_model_option.feature_code= #{featureCode} </if> <if test='featureName != null'> AND plm_feature_lib.feature_name= #{featureName} </if> <if test='optionCode != null'> AND plm_model_option.option_code= #{optionCode} </if> <if test='optionName != null'> AND plm_option_lib.option_name= #{optionName} </if>

現在進行模糊查詢的代碼:

<if test='searchStr!=null and searchStr!=’’'> AND CONCAT(plm_model_option.feature_code,plm_feature_lib.feature_name,plm_model_option.option_code,plm_option_lib.option_name) LIKE CONCAT (’%’, #{searchStr},’%’)</if>

補充:最新Mybatis關鍵字模糊查詢結果檢索多個字段解決方案

Mybatis用戶名模糊查詢,賬號模糊查詢我相信大家都會。那么如何輸入關鍵字之后既可以查詢到用戶名的結果又可以查詢到賬號的結果呢?

我這里設定的是id和username兩個字段的關鍵字模糊查詢。

先看下效果圖:

關鍵字搜索之前的列表數據

Mybatis 實現一個搜索框對多個字段進行模糊查詢

關鍵字搜索之后的數據

Mybatis 實現一個搜索框對多個字段進行模糊查詢

實現核心代碼:

<select resultType='com.swkj.pojo.Member'> SELECT * FROM tb_member WHERE 1=1 <if test='keyword!=’’ and keyword!=null'> <!--bind 標簽的兩個屬性都是必選項, name 為綁定到上下文的變量名,value為OGNL表達式。--> <bind name='pattern' value='’%’ + keyword + ’%’'/> and CONCAT(username,id) like #{pattern} </if> <if test='sdate!=’’ and sdate!=null'> and starttime>=#{sdate} </if> <if test='edate!=’’ and edate!=null'> and starttime&lt;=#{edate} </if> limit #{m},#{n} </select>原理分析:

這里其實就是在where條件后面將id和username通過concat()函數連接了起來,然后在對關鍵字進行模糊查詢,就能得到自己想要的結果了。So easy!

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 独山县| 香格里拉县| 景宁| 措勤县| 五大连池市| 晋城| 西和县| 时尚| 精河县| 仁怀市| 炉霍县| 贵溪市| 温州市| 延川县| 贺州市| 安福县| 靖州| 无极县| 海原县| 阿拉善左旗| 罗源县| 民乐县| 湖州市| 息烽县| 平安县| 五河县| 商水县| 久治县| 新疆| 铅山县| 涟水县| 西安市| 当雄县| 耿马| 正蓝旗| 汽车| 伊金霍洛旗| 万安县| 贡山| 玉溪市| 郓城县|