当前位置: 移动技术网 > IT编程>开发语言>Java > mybatis 使用concat 模糊查询

mybatis 使用concat 模糊查询

2020年07月30日  | 移动技术网IT编程  | 我要评论
<select id="queryByKeyWord" resultType="com.mingdutech.xelerator.eln.dto.ApparatusDto">
        select distinct b.*
        from base_apparatus b
        left join base_apparatus_column c
        on b.ID = c.apparatus_id
        <if test="keyWord != null">
            <where>
                CONCAT( IFNULL(b.name,''),
                IFNULL(code,''),
                IFNULL(serial,''),
                IFNULL(location,''),
                IFNULL(remark,''),
                IFNULL(b.create_user,''),
                IFNULL(b.update_user,''),
                IFNULL(c.field_value,''),
                IFNULL(batch_no,'') )
                like CONCAT('%',#{keyWord},'%')
            </where>
        </if>
    </select>

concat() 函数用于将多个字符串拼接成一个字符串
本举例:keyWord为空查询所有,keyWord不为空,检索所有contact中所有字段匹配的内容。
注意:所有字段需要IFNULL判断,否则某字段为空可能会导致查询结果丢失一条记录

本文地址:https://blog.csdn.net/weixin_41830501/article/details/107654392

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网