mybatis批量操作

List类型

Mapper.java

public int updateAccount(List<orderjob> orderJobs);</orderjob>

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);</orderjob>

那么 collerciton=”Param1″

Map类型

Mapper.java

@Data
public class BizMnCreateTableBO {
    // &#x8868;&#x540D;&#x79F0;
    private String tableName;
    // &#x5B57;&#x6BB5;
    private Map<string,string> parmes;
    }
}</string,string>

Mapper.xml

<update id="createNewTable" parametertype="com.hongyums.system.domain.vo.BizMnCreateTableBO">
    CREATE TABLE ${tableName} (
      id bigint(20) NOT NULL AUTO_INCREMENT comment '&#x5408;&#x540C;&#x6A21;&#x677F;&#x7F16;&#x53F7;',
      dlmc varchar(20) comment '&#x767B;&#x5F55;&#x540D;&#x79F0;',
      <foreach index="key" item="value" collection="parmes" separator=",">
       ${key} varchar(50) DEFAULT NULL comment #{value}
      </foreach>
      , PRIMARY KEY (id))
</update>

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

mybatis批量操作

Original: https://www.cnblogs.com/cking98/p/16351178.html
Author: 林间小路
Title: mybatis批量操作

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/620924/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球