Spring boot Mysql Foreach 语句使用

我们在对数据库操作时,可能或涉及批量操作:
例如:需要查询status字段为0,1,2 的数据,这时就可以使用Foreach语句直接在mapper层对数据库操作。
具体使用如下:

	 "select *"+
	 "from user"+
 	"where status in"+
 	"<foreach collection=\"statusList\"  item=\"item\"  index=\"index\" open=\"		(\" separator=\",\" close=\")\">"+
	 "#i{tem}"+
	 "</foreach>"+

传入条件的list

 <foreach collection="kp_title" index="index" item="item" open="(" separator="," close=")">
 #{item}
</foreach>
发布了54 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/liutaiyi8/article/details/83930314