<sql id="query_user_where">
<if test="userCustom!=null">
<if test="userCustom.username!=null and userCustom.username!=''">
and username like '%${userCustom.username}%'
</if>
<if test="userCustom.sex!=null and userCustom.sex!=''">
and sex = #{userCustom.sex}
</if>
<!-- 最终拼接的效果:
select id,username,birthday From user where username like "%小明%" and id in(16,22,25)
-->
<!-- 根据id集合查询用户信息 -->
<!--
collection:集合的属性,pojo包装类中放置集合的字段名
open:开始循环要遍历的串,从 and id in(开始循环
close:结束循环所要拼接的串
item:每次循环取到的对象,名称自定义
separator:每两次循环中间拼接的串
-->
<foreach collection="ids" open="and id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</if>
</sql>mybatis中foreach的使用
最新推荐文章于 2023-05-16 15:25:27 发布
3677

被折叠的 条评论
为什么被折叠?



