mybatis动态sql中where标签的使用
2016-08-11 19:44
661 查看
where标记的作用类似于动态sql中的set标记,他的作用主要是用来简化sql语句中where条件判断的书写的,如下所示:
<select id="selectByParams" parameterType="map" resultType="user">
select * from user
<where>
<if test="id != null ">id=#{id}</if>
<if test="name != null and name.length()>0" >and name=#{name}</if>
<if test="gender != null and gender.length()>0">and gender = #{gender}</if>
</where>
</select>
在上述SQL中加入ID的值为null的话,那么打印出来的SQL为:select * from user where name="xx" and gender="xx"
where 标记会自动将其后第一个条件的and或者是or给忽略掉
<select id="selectByParams" parameterType="map" resultType="user">
select * from user
<where>
<if test="id != null ">id=#{id}</if>
<if test="name != null and name.length()>0" >and name=#{name}</if>
<if test="gender != null and gender.length()>0">and gender = #{gender}</if>
</where>
</select>
在上述SQL中加入ID的值为null的话,那么打印出来的SQL为:select * from user where name="xx" and gender="xx"
where 标记会自动将其后第一个条件的and或者是or给忽略掉
相关文章推荐
- mybatis的动态SQL(三)where、set、trim标签的使用
- mybatis动态sql中where标签的使用
- mybatis动态sql中的trim标签的使用
- mybatis动态sql中的trim标签的使用
- mybatis动态sql中的trim标签的使用
- MyBatis动态SQL中trim标签的使用参数
- mybatis动态sql中的trim标签的使用
- mybatis动态查询 sql标签和include标签的使用
- MyBatis动态SQL<choose>标签的使用
- MyBatis--动态SQL---where标签
- MyBatis动态SQL中trim标签的使用
- mybatis动态SQL中的set标签的使用
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- Mybatis中动态SQL(if,where,foreach 的使用)
- mybatis动态sql中的trim标签的使用
- mybatis动态sql中foreach标签的使用
- mybatis动态sql中的trim标签的使用
- MyBatis使用动态SQL标签的小陷阱
- myBatis的动态SQL之标签的使用
- mybatis动态sql中的trim标签的使用