[Mybatis]- 一个关键词匹配多个列进行模糊查询

内容分享2小时前发布
0 0 0

方式1-使用mysql函数 INSTR(str, substr)

  • INSTR(str, substr) 在指定的字符串(str)中,搜索指定的字符(substr),返回发现指定的字符的位置;
  • CONCAT_WS:把需要查询的字段数据拼接起来

  <select id="queryPageListByParams"  parameterType="java.util.Map" resultMap="userMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM user u
        WHERE 1 = 1
        <!--地址模糊查询 -->
        <if test="params.address!= null and params.address!=   ">
            and res.name like CONCAT(CONCAT( % ,#{params.name}), % )
        </if>
        <if test="params.keyWorod != null and params.keyWorod!=   ">
            and INSTR(CONCAT_WS("-", name, sex), #{keyword}) > 0
        </if>
        order  by  create_time desc
    </select>

© 版权声明

相关文章

暂无评论

none
暂无评论...