目录

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>

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