您的位置:首页 > 数据库

mybatis的动态sql标签

2017-05-16 09:46 393 查看
mybatis的动态sql

标签
1. <if test="条件成立">
拼接的sql
</if>
2. <where>
<if test="条件 and  条件">
and ...
</if>
<if test="条件 and  条件">
and ...
</if>
</wnere>
说明:where标签在最后会将第一个条件的"and"给去掉,以防止sql拼写异常
3. <set>
<if test="条件">
...,
</if>
<if test="条件">
...,
</if>
</set>
说明:set标签在最后会将最后一个set的“,”给去掉,以防止sql拼写异常
4. <choose>
<when test="条件">
。。。
</when>
<otherwise>
。。。
</otherwise>
</choose>
5. 
<select id="selectById" resultType="com.zyj.test.User">
select
<include refid="usercolumn"></include>
from tb_user
<where>
id in
<foreach collection="ids" open="(" close=")" item="userid" separator=",">
#{userid}
</foreach>
</where>
</select>


说明foreach循环可以便来List,Set,Map集合,当为Map集合时自定义为key或value,默认为Value
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: