mybatis 注解形式设置批量新增、批量更新数据

1. 批量更新:

    @Update({"<script>" +
            "<foreach collection="smsConfigTemplateList" item="item" separator=";">" +
            " UPDATE" +
            " mt_message_template" +
            " SET pushapp_type = #{item.pushAppType, jdbcType=VARCHAR}, " +
            "  message_title = #{item.messageTitle, jdbcType=VARCHAR}, " +
            "  message_content = #{item.messageContent, jdbcType=VARCHAR}, " +
            "  template_id_weixin = #{item.emplateIdWeixin, jdbcType=VARCHAR}, " +
            "  template_weixin = #{item.templateWeixin, jdbcType=VARCHAR}, " +
            "  template_alipay = #{item.templateAlipay, jdbcType=VARCHAR}, " +
            "  template_id_zhifubao = #{item.templateIdZhifubao, jdbcType=VARCHAR}, " +
            "  modifiedon = #{item.modifiedon, jdbcType=TIMESTAMP}, " +
            "  modifiedby = #{item.modifiedby, jdbcType=VARCHAR} " +
            "  WHERE " +
            "   message_template_id = #{item.messageTemplateId, jdbcType=VARCHAR} " +
            "  AND deletion_state = '0' " +
            "</foreach>" +
            "</script>"})
    void update(@Param("smsConfigTemplateList") List<SmsConfigTemplate> smsConfigTemplateList);

2. 批量新增:

    @Insert({"<script>" +
            "INSERT INTO  mt_message_template (" +
            "message_template_id,
" +
            "message_template_head_id,
" +
            "message_title,
" +
            "message_content,
" +
            "pushapp_type,
" +
            "platform_hospital_id,
" +
            "template_id_weixin,
" +
            "template_weixin,
" +
            "template_alipay,
" +
            "template_id_zhifubao,
" +
            "createdby,
" +
            "createdon,
" +
            "modifiedby,
" +
            "modifiedon,
" +
            "deletion_state)" +
            "values  " +
            "<foreach collection="mtMessageTemplateList" item="item" separator=",">" +
            "(#{item.messageTemplateId}, #{item.messageTemplateHeadId}, " +
            "#{item.messageTitle}, #{item.messageContent}, " +
            "#{item.pushAppType}, #{item.platformHospitalId}, " +
            "#{item.emplateIdWeixin}, #{item.templateWeixin}, " +
            "#{item.templateAlipay}, #{item.templateIdZhifubao}, " +
            "#{item.createdby}, #{item.createdon}, " +
            "#{item.modifiedby}, #{item.modifiedon}, " +
            "#{item.deletionState})" +
            "</foreach>" +
            "</script>"})
    void insert(@Param("mtMessageTemplateList") List<MtMessageTemplate> mtMessageTemplateList);

原文地址:https://www.cnblogs.com/miaoying/p/10007078.html