在xml中,特殊符号的转义写法如下:
< <
> >
<> <>
& &
' '
" "
也可以使用<![CDATA[ ]]>
符号进行说明,将此类符号不进行解析
<![CDATA[ sql语句 ]]>
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},'%')