mybatis like %% 基于mybatis like %%的问题

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

mybatis like %% 基于mybatis like %%的问题

intelrain   2021-10-01 我要评论
想了解基于mybatis like %%的问题的相关内容吗,intelrain在本文为您仔细讲解mybatis like %%的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mybatis,like,mybatis,%%,下面大家一起来学习吧。

mybatis like %%问题

<select id="getMaxNotOnlineInfoByConditon" resultType="com.shishike.susie.entity.CustomConfirmInfo">
 
SELECT *
FROM t_customconfirminfo
WHERE (if(#{pduName,jdbcType=VARCHAR} IS NULL, 0 = 0, pduname = #{pduName,jdbcType=VARCHAR})
   AND if(#{moduleName,jdbcType=VARCHAR} IS NULL, 0 = 0, modulename = #{moduleName,jdbcType=VARCHAR})
   AND if(#{env,jdbcType=VARCHAR} IS NULL, 0 = 0, confirminfo = #{env,jdbcType=VARCHAR})
   AND if(#{ossAddress,jdbcType=VARCHAR} IS NULL, 0 = 0, ossaddress = #{ossAddress,jdbcType=VARCHAR})
   AND if(#{branch,jdbcType=VARCHAR} IS NULL, 0 = 0,  branch like concat(concat('%',#{branch,jdbcType=VARCHAR}),'%'))
   AND if(#{confirmId,jdbcType=BIGINT} IS NULL, 0 = 0, id > #{confirmId,jdbcType=BIGINT})
   AND onlineinfo is null)
ORDER BY CREATED DESC
LIMIT 1
</select>

mybatis 关于like的处理

1、利用"%"对入参进行拼接

2、SQL语句字符串拼接

SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');

3、bind标签

<select id="findUserByFuzzyEmail" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select id,username,email,status,createtime,updatetime from tb_user
        <bind name="pattern" value="'%'+_parameter.getEmail() +'%'" />
        <where>
            <if test="email != null and email != ''">
                email like #{pattern}
            </if>
        </where>
    </select>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们