mybatis中LIKE模糊查询

mybatis中LIKE模糊查询

mybatis 中模糊查询有几种方式的,我主要用了下面的方式
1. 使用关键字CONCAT拼接,如下
<select id="getByTitleAndCorpAccId" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from UMP_MSG_TEMPLATE
        where CORP_ACC_ID = #{corpAccId,jdbcType=INTEGER}
        <if test="title != null">
            AND TITLE like CONCAT('%', #{title,jdbcType=VARCHAR}, '%')
        </if>
    </select>
2. 使用locate()函数

locate()函数: 判断字符串(string)中是否包含另一个字符串(subStr)
locate(subStr,string) :函数返回subStr在string中出现的位置

<select id="searchApiAccountList" parameterType="java.util.Map"
            resultType="com.pccwhkt.ump.portal.umportal.sys.user.bean.UmgLoginAcc">
        select <include refid="Base_Column_List" />
        from UMG_LOGIN_ACC
        <if test="name != null and name != ''">
            where LOCATE(#{corp_id}, CORP_ID)>0
        </if>

        <if test="login_id != null and login_id != ''">
            <choose>
                <when test="corp_id != null and corp_id != ''">
                    and LOCATE(#{corp_name}, CORP_ACC_NAME)>0
                </when>
                <otherwise>
                    where LOCATE(#{corp_name}, CORP_ACC_NAME)>0
                </otherwise>
            </choose>
        </if>

        <if test="status != null and status != ''">
            <choose>
                <when test="(corp_id != null and corp_id != '') or (corp_name != null and corp_name != '')">
                    and LOCATE(#{status}, STATUS)>0
                </when>
                <otherwise>
                    where LOCATE(#{status}, STATUS)>0
                </otherwise>
            </choose>
        </if>

        <if test="msisdn != null and msisdn != ''">
            <choose>
                <when test="(corp_id != null and corp_id != '') or (corp_name != null and corp_name != '') or (status != null and status != '')">
                    and LOCATE(#{type}, TYPE)>0
                </when>
                <otherwise>
                    where LOCATE(#{type}, TYPE)>0
                </otherwise>
            </choose>
        </if>
    </select>
其他方式请参考这篇文章:https://blog.csdn.net/zhenwei1994/article/details/81876278
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值