Mybatis中的if,else,获取新增id

<insert id="insertServiceEquip" parameterType="Map">
<selectKey resultType="int" keyProperty="seq" order="BEFORE">

《获取新增id》
select
SEQ_EQUIPSERVICE.NEXTVAL as seq from dual
</selectKey>
INSERT INTO EQUIP_SERVICE
<trim prefix="(" suffix=")" suffixOverrides=",">

《这个choose下的when,otherwise就是if,else了》

<choose>

<when test="serviceAreaId !=null">
<if test="serviceAreaId != null">SEQ,</if>
</when>
<otherwise>
<if test="seq != null">SEQ, </if>
</otherwise>
</choose>
<if test="equipId != null">EQUIP_ID,</if>
<if test="buildId != null">BUILD_ID,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<choose>
<when test="serviceAreaId !=null">
<if test="serviceAreaId != null">#{serviceAreaId},</if>
</when>
<otherwise>
<if test="seq != null">#{seq}, </if>
</otherwise>
</choose>
<if test="equipId != null"> #{equipId}, </if>
<if test="buildId != null"> #{buildId}, </if>
</trim>
</insert>

posted @ 2017-06-19 16:15  黑土浊墨悟吾心  阅读(221)  评论(0编辑  收藏  举报