Mybatis批量更新传map参数,设置允许批量执行sql

多条数据更新操作场景还是非常多的,每次碰到类似问题还是需要稍微百度一下复制,

so,与其每次看别人博客不如自己也记录一下,方便以后回忆并使用也方便了大家;

不过需要批量,记得一定检查一下是否有配置允许批量更新,如果已设置请忽略;

&allowMultiQueries=true 允许批量更新

spring.datasource.jdbc-url=jdbc:mysql://xx.xx.xx.xx:3306/数据库名?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true

 Service、mapper接口:

public int updateCheckStatusByProjectIds( Map param);

 mapper.xml :

  
    
    
      update person_info set
      check_people = #{params.checkPeople},
      check_status = #{params.checkStatus},
      check_date = #{params.checkDate}
      where person_id = #{params.personId}
    
  

Serviceimpl实现类:

public int updateCheckStatusByProjectIds(HttpServletRequest request, String projectId, String status){
        if ("success".equals(status)){
            status = Constant.SUCCESS_STATE;
        }else{
            status = Constant.REJECT_STATE;
        }
        Map map = new HashMap();
        String[] arr  = projectId.split(",");
        User user = SessionUtils.getUser(request);
        List list = new ArrayList();
        for(int i=0;i

有问题还请留言,大神多多指教!

你可能感兴趣的:(Java)