mybatis 批量更新

mybatis 批量更新,首先要在数据库连接 url 上添加配置 &allowMultiQueries=true,因为 mysql 默认不支持批量更新,所以需要开发人员手动设置

spring:
  datasource:
    url:  jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true
    driver-class-name:  com.mysql.jdbc.Driver
    username:  root
    password:  root

 

定义 mapper 接口

package com.music.mapper;

import com.music.bean.Music;
import org.apache.ibatis.annotations.Param;
import java.util.List;

public interface MusicMapper {

    //批量更新
    int updataMusicForeach(@Param("list") List list);
}

 

mapper.xml 文件





    
        
        
    

    
    
        
            update m_music set m_music_problem = #{item.mMusicProblem} where m_music_id = #{item.mMusicId}
        
    
  

 

你可能感兴趣的:(mybatis)