您的位置:首页 > 数据库 > MySQL

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

2017-07-06 15:57 429 查看
原文链接:blog.csdn.net/wangshuang1631/article/details/53488188

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

<          <
>          >
<>      <>
&         &
'        '
"        "
1
也可以使用
<![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>
4
3.CONCAT

like concat('%',#{param},'%')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql