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>