mybatis批量操作

List类型

Mapper.java

public int updateAccount(List<OrderJob> orderJobs);

Mapper.xml

<update id="updateAccount" parameterType="com.hongyums.quartz.domain.OrderJob">
    update biz_mn_account
    set
    <trim prefix="ZJE=case " suffix="end,">
        <foreach collection="list" item="item" >
            when dlmc=#{item.dlmc} then #{item.zje}
        </foreach>
    </trim>

    <trim prefix="YQRZJE=case " suffix="end,">
        <foreach collection="list" item="item" >
            when dlmc=#{item.dlmc} then #{item.yqrzje}
        </foreach>
    </trim>

    <trim prefix="YXFJE=case " suffix="end,">
        <foreach collection="list" item="item" >
            when dlmc=#{item.dlmc} then #{item.yxfje}
        </foreach>
    </trim>
    GXSJ=SYSDATE()
    where DLMC in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
        #{item.dlmc}
    </foreach>

</update>

如果是Array的话,collerciton="array"

collerciton=list 和array 是mybaits默认的参数名称,如果你入参中设置了 @Parame

public int updateAccount(@Parame("Param1") List<OrderJob> orderJobs);

那么  collerciton=“Param1”

 

Map类型

Mapper.java

@Data
public class BizMnCreateTableBO {
    // 表名称
    private String tableName;
    // 字段
    private Map<String,String> parmes;
    }
}

Mapper.xml

<update id="createNewTable" parameterType="com.hongyums.system.domain.vo.BizMnCreateTableBO">
    CREATE TABLE ${tableName} (
      id bigint(20) NOT NULL AUTO_INCREMENT comment '合同模板编号',
      dlmc varchar(20) comment '登录名称',
      <foreach index="key" item="value" collection="parmes" separator=",">
       ${key} varchar(50) DEFAULT NULL comment #{value}
      </foreach>
      , PRIMARY KEY (id))
</update>

 我尝试 将${key}改为#{key} 但是发现报错,暂不知原因。

 

posted @ 2022-06-14 08:55  林间小路  阅读(258)  评论(0)    收藏  举报