需求:参数传入一个list,根据list中的数据从数据库中取数据,如果list为空则返回所有
Mapper接口
List<User> selectByName(@Param("names") List<String> names);
sql
<select id="selectByName" resultMap="BaseResultMap">
select
*
from User
where 1=1
<if test="names != null and names.size()>0">
and Name in
<foreach collection="names" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</if>
</select>
最后
以上就是飞快蜗牛最近收集整理的关于MyBatis if foreach嵌套的全部内容,更多相关MyBatis内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复