日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

MybatisPlus的UpdateWrapper和QueryWrapper的區(qū)別

作者:柯柯不會(huì)Java 更新時(shí)間: 2022-10-11 編程語(yǔ)言

MybatisPlus的UpdateWrapper和QueryWrapper的區(qū)別

查詢

測(cè)試代碼

@Test
public void testWrapper(){
    LambdaQueryWrapper<Picture> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    lambdaQueryWrapper.eq(Picture::getEnterpriseCode, "FASTECH_DEV");
    lambdaQueryWrapper.eq(Picture::getServerCode, "HL_FIRE_SAFE");
    lambdaQueryWrapper.eq(Picture::getId, 296);
    List<Picture> pictureList1 = pictureMapper.selectList(lambdaQueryWrapper);
    System.out.println("QueryWrapper查詢出來的結(jié)果:" + pictureList1);

    LambdaUpdateWrapper<Picture> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
    lambdaUpdateWrapper.eq(Picture::getEnterpriseCode, "FASTECH_DEV");
    lambdaUpdateWrapper.eq(Picture::getServerCode, "HL_FIRE_SAFE");
    lambdaUpdateWrapper.eq(Picture::getId, 296);
    List<Picture> pictureList2 = pictureMapper.selectList(lambdaQueryWrapper);
    System.out.println("UpdateWrapper查詢出來的結(jié)果:" + pictureList2);
}

運(yùn)行結(jié)果

在這里插入圖片描述

結(jié)論

對(duì)于查詢來說,兩者基本沒啥區(qū)別,但是一般查詢都是用QueryWrapper

修改

源數(shù)據(jù)

在這里插入圖片描述

QueryWrapper測(cè)試代碼

@Test
public void testWrapper(){
    LambdaQueryWrapper<Picture> lambdaQueryWrapper = new LambdaQueryWrapper<>();
    Picture picture = new Picture();
    picture.setPictureType("111");
    lambdaQueryWrapper.eq(Picture::getId, 296);
    pictureMapper.update(picture, lambdaQueryWrapper);
}

運(yùn)行結(jié)果

在這里插入圖片描述

UpdateWrapper測(cè)試代碼

@Test
public void testWrapper(){
    LambdaUpdateWrapper<Picture> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
  	lambdaUpdateWrapper.eq(Picture::getId, 296); // 表示需要修改數(shù)據(jù)的查詢條件,不設(shè)置默認(rèn)修改全部
  	lambdaUpdateWrapper.set(Picture::getPictureType, "222");
  	lambdaUpdateWrapper.set(Picture::getEnterpriseCode, null);
  	pictureMapper.update(null, lambdaUpdateWrapper);
}

運(yùn)行結(jié)果

在這里插入圖片描述

結(jié)論

QueryWrapper可以根據(jù)id修改,也可以根據(jù)QueryWrapper構(gòu)建的查詢條件進(jìn)行修改,后者修改傳入一個(gè)映射實(shí)體,而且默認(rèn)不會(huì)把映射實(shí)體的空值映射到數(shù)據(jù)庫(kù),如果想將數(shù)據(jù)庫(kù)某個(gè)屬性置空,使用UpdateWrapper

原文鏈接:https://blog.csdn.net/qq_46601365/article/details/123628358

欄目分類
最近更新