mybatis xml文件中的大于、小于、及like模糊查询的写法

在xml中,特殊符号的转义写法如下

    &lt;          < 
    &gt;          >  
    &lt;&gt;      <>
    &amp;         & 
    &apos;        '
    &quot;        "

也可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析

<![CDATA[ sql语句 ]]>  
  • 1

mysql like的写法:

1.传入参数中直接加入%%

    param.setUsername("%CD%");
    param.setPassword("%11%");
<select  id="selectPersons" resultType="person" parameterType="person">
    select id,sex,age,username,password from person where true 
    <if test="username!=null"> AND username LIKE #{username}</if>
    <if test="password!=null">AND password LIKE #{password}</if>
</select>

2.bind标签

<select id="selectPersons" resultType="person" parameterType="person">
    <bind name="pattern" value="'%' + _parameter.username + '%'" />
        select id,sex,age,username,password from person
        where username LIKE #{pattern}
</select>

3.CONCAT

 like concat('%',#{param},'%') 

猜你喜欢

转载自blog.csdn.net/suixinsuoyu12519/article/details/79532519
今日推荐