栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis的批量查询,批量更新

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis的批量查询,批量更新

批量查询
  1. 在mapper层定义查询方法

    注@Param参数是绑定xml里面的collection参数

List queryByIds(@Param("idList") List idList);
  1. xml文件中写SQL语句

   select * from test_table
   
      
         id in
        
            #{item}
        
      
  

批量更新操作

首先假设项目已经连接好数据库,定义好了实体类 且实体类名为MybatisDTO;

id主键
address地址

实现需求为通过id批量更新地址信息。

Class MybatisDTO{
    Integer id;
    String address;
}

接口Controller

@ApiOperation("批量更新")
@PutMapping(value = "/batchUpdate")
public ResponseEntity batchUpdate(@PathVariable("organizationId") Long tenantId,
                                  String defaultAddress,
                                  @RequestBody List mybatisDTOS){
        mybatisService.batchUpdate(mybatisDTOS,defaultAddress);
        return ResponseEntity.ok(HttpStatus.OK);
    }

service层

public interface BatchUpdateService{
    void batchUpdate(List mybatisDTOS, String defaultAddress);
}

public class BatchUpdateServiceImpl extends BatchUpdateService{
    @Autowird
    private BatchUpdateMapper batchUpdateMapper;
    public void batchUpdate(List mybatisDTOS,String defaultAddress){
        batchUpdateMapper.batchUpdate(mybatisDTOS,defaultAddress);
    }
}

mapper层

public interface BatchUpdateMapper{
    void batchUpdate(List mybatisDTOS,String defaultAddress);
}

XML文件

    
        update hcbm_sign_archive
        
        
                #{defaultAddress}
        
        
        
            
                when #{a.id} then #{a.archiveAddress}
            
        
        
        
        where
        
            id=#{a.id}
        
    
//这种方式一直报错 未解决

item.archiveAddress}-->
item.id};-->

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1005671.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号