mybatis的动态sql标签

来源:互联网 发布:淘宝网三轮车 编辑:程序博客网 时间:2024/06/02 02:29
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
原创粉丝点击