foreach
choose为一个整体,
when表示if ,(when可重复,即实现if..else if..else if..)
otherwise表示else。

 

mybatis并没有if..else,在mybatis的sql mapper文件中,条件判断要用choose..when..otherwise。
<choose>
            <when test="ids != null and ids.size() != 0">
                AND id IN
                <foreach collection="ids" item="usId" open="(" close=")" separator=",">
                    #{usId}
                </foreach>
            </when>
            <otherwise>
                AND id IN(0)
            </otherwise>
        </choose>

 

 

 

<!--updateCostType 批量修改-->
    <update id="updateCostTypeBatch" parameterType="list">
        <foreach collection="list" item="cost" separator=";">
            UPDATE t_cost_type
            SET type_name=#{cost.typeName},
            modify_id=#{cost.modifyId},
            modify_time=#{cost.modifyTime}
            WHERE id=#{cost.id}
        </foreach>
    </update>
<!--insertCostTypeList 批量新增二级-->
    <insert id="insertCostTypeList" parameterType="list">
        INSERT INTO t_cost_type(type_name,father_id,`status`,create_id,create_time) VALUES
        <foreach collection="list" item="cost" separator=",">
            (#{cost.typeName},#{cost.fatherId},#{cost.status},#{cost.createId},#{cost.createTime})
        </foreach>
    </insert>

 

 

plus:  

XXService.insertBatch()
XXService.updateBatchById()
xxService.deleteBatchIds()
xxService.selectBatchIds

 

plus的优势就是减少开发者去写太简单的增删改查的sql,自动生成拼接好的sql