mybatise 的foreach标签中执行两条insert sql,第二条可以获取第一条的主键值吗主键是通过函数动态获取的
各位大神,下面的??处的值该怎么取<insertid="xxx"parameterType="java.util.HashMap">BEGIN<iftest="list....
各位大神,下面的??处的值该怎么取
<insert id="xxx" parameterType="java.util.HashMap">
BEGIN
<if test="list.size() > 0">
<foreach collection="list" item="item" index="index" separator="" close="">
<choose>
<when test="item.id != null and item.id != ''">
update maintable set name=#{item.name} where id = #{item.id};
</when>
<otherwise>
insert into maintable(id,name)
select getkey('maintable'),'xxx' from dual;
insert into childtable(id,maintableid,code) values(getkey('childtable'),??,#{item.code});
</otherwise>
</choose>
</foreach>
</if>
END;
</insert> 展开
<insert id="xxx" parameterType="java.util.HashMap">
BEGIN
<if test="list.size() > 0">
<foreach collection="list" item="item" index="index" separator="" close="">
<choose>
<when test="item.id != null and item.id != ''">
update maintable set name=#{item.name} where id = #{item.id};
</when>
<otherwise>
insert into maintable(id,name)
select getkey('maintable'),'xxx' from dual;
insert into childtable(id,maintableid,code) values(getkey('childtable'),??,#{item.code});
</otherwise>
</choose>
</foreach>
</if>
END;
</insert> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询