学无先后,达者为师

网站首页 java综合 正文

Mybatis中like搭配concat的写法详解_java

作者:天真.。   更新时间: 2022-04-03 java综合

Mybatis like搭配concat写法

在Mybatis中的写法

 <!--concat Mysql和 Oracle区别 ,不存在sql注入-->
  <select id="findUserByLikeName3" parameterType="java.lang.String" resultMap="user">
      select * from t_user where name like concat('%',#{name,jdbcType=VARCHAR},'%')
  </select>

Mybatis concat()函数模糊查询

mysql 的 like,建议 like concat() 组合,可以防止sql注入

    <select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
        select info_id,login_name,ipaddr,login_location,browser,os,status,msg,login_time from sys_logininfor
        <where>
            <if test="ipaddr != null and ipaddr != ''">
                AND ipaddr like concat('%', #{ipaddr}, '%')
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="loginName != null and loginName != ''">
                AND login_name like concat('%', #{loginName}, '%')
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(login_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(login_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
栏目分类
最近更新