Mybatis 的foreach 可以嵌套吗
2个回答
2016-09-30
展开全部
官方给的test是可以的
<select id="nestedSelect" parameterType="Parameter" resultType="map">
select *
from names
<where>
<foreach collection="names" item="name" separator="or">
<foreach collection="name.firstNames" item="firstName" separator="or">
(lastName = #{name.lastName} and firstName = #{firstName})
</foreach>
</foreach>
</where>
</select>
http://code.google.com/p/mybatis/source/browse/trunk/src/test/java/org/apache/ibatis/submitted/nested/?r=3467
Junit Test
NestedForEachTest.java
NestedForEach.xml
<select id="nestedSelect" parameterType="Parameter" resultType="map">
select *
from names
<where>
<foreach collection="names" item="name" separator="or">
<foreach collection="name.firstNames" item="firstName" separator="or">
(lastName = #{name.lastName} and firstName = #{firstName})
</foreach>
</foreach>
</where>
</select>
http://code.google.com/p/mybatis/source/browse/trunk/src/test/java/org/apache/ibatis/submitted/nested/?r=3467
Junit Test
NestedForEachTest.java
NestedForEach.xml
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-09-30 · 知道合伙人软件行家
关注
展开全部
官方给的test是可以的
<select id="nestedSelect" parameterType="Parameter" resultType="map">
select *
from names
<where>
<foreach collection="names" item="name" separator="or">
<foreach collection="name.firstNames" item="firstName" separator="or">
(lastName = #{name.lastName} and firstName = #{firstName})
</foreach>
</foreach>
</where>
</select>
http://code.google.com/p/mybatis/source/browse/trunk/src/test/java/org/apache/ibatis/submitted/nested/?r=3467
Junit Test
NestedForEachTest.java
NestedForEach.xml
<select id="nestedSelect" parameterType="Parameter" resultType="map">
select *
from names
<where>
<foreach collection="names" item="name" separator="or">
<foreach collection="name.firstNames" item="firstName" separator="or">
(lastName = #{name.lastName} and firstName = #{firstName})
</foreach>
</foreach>
</where>
</select>
http://code.google.com/p/mybatis/source/browse/trunk/src/test/java/org/apache/ibatis/submitted/nested/?r=3467
Junit Test
NestedForEachTest.java
NestedForEach.xml
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询