1.MP的增加操作

 @Testpublic void insert(){User user = new User();user.setName("向中");user.setAge(23);user.setEmail("xd@baomidou.com");user.setManagerId(1088248166370832385L);user.setCreateTime(LocalDateTime.now());//返回影响记录数int rows = userMapper.insert(user);System.out.println("影响记录数:"+rows);}

2.MP的查询操作

(1)selectById 根据 ID 查询

  @Testpublic void selectById(){User user = userMapper.selectById(1088248166370832385L);System.out.println(user);}

(2)selectBatchIds 查询(根据ID 批量查询)

  @Testpublic void selectByIds(){List<Long> asList = Arrays.asList(1088250446457389058L, 1094592041087729666L, 1186555441707827201L);List<User> userList = userMapper.selectBatchIds(asList);userList.forEach(System.out::println);}

(3)selectByMap 查询(根据 columnMap 条件)

    @Testpublic void selectByMap(){//map.put("name","王天风")//map.put("age",25)//where name = "王天风" and age=30Map<String,Object> columnMap = new HashMap<>();columnMap.put("name","王天风");columnMap.put("age",25);List<User> userList = userMapper.selectByMap(columnMap);userList.forEach(System.out::println);}

3.MP的更新操作

(1)updateById 根据主键id更新

  @Testpublic void updateById(){User user = new User();user.setId(1088248166370832385L);user.setAge(30);user.setEmail("wtf2@baomidou.com");int rows = userMapper.updateById(user);System.out.println("影响记录数:"+ rows);}

(2)UpdateWrapper 更新,多条属性操作
1.多条属性更新

   @Testpublic void update(){//  User whereUser = new User();//  whereUser.setName("大boss");//  UpdateWrapper<User> updateWrapper = new UpdateWrapper<>(whereUser);//  updateWrapper.eq("age",41);UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();updateWrapper.eq("name","大boss").eq("age",41);User user = new User();user.setAge(41);user.setEmail("bigboss2@baomidou.com");int rows = userMapper.update(user, updateWrapper);System.out.println("影响记录数:" + rows);}

2.少数属性更新,加上set

  @Testpublic void update2(){UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();updateWrapper.eq("name","大boss").eq("age",41).set("age",42);int rows = userMapper.update(null, updateWrapper);System.out.println("影响记录数:" + rows);}

(3)LambdaUpdateWrapper 更新操作,可以防止sql注入
1.lambdaUpdateWrapper 更新

  @Testpublic void updateByLambdaWrapper(){LambdaUpdateWrapper<User> lambdaUpdateWrapper = Wrappers.<User>lambdaUpdate();lambdaUpdateWrapper.eq(User::getName,"大boss").eq(User::getAge,42).set(User::getAge,43);int update = userMapper.update(null, lambdaUpdateWrapper);System.out.println(update);}

2.LambdaUpdateChainWrapper 链式更新

 @Testpublic void updateByLambdaWrapperChain(){boolean update = new LambdaUpdateChainWrapper<User>(userMapper).eq(User::getName, "大boss").eq(User::getAge, 43).set(User::getAge, 44).update();System.out.println(update);}

4.MP的删除操作

(1)deleteById

 @Testpublic void deleteById() {int delete = userMapper.deleteById(1186569110046949378L);System.out.println(delete);}

(2)deleteByMap

  @Testpublic void deleteByMap() {Map<String,Object> map = new HashMap<>();map.put("name","向前");map.put("age",23);int deleteByMap = userMapper.deleteByMap(map);System.out.println(deleteByMap);}

(3)deleteBatchIds

  @Testpublic void deleteByBatchIds() {List<Long> list = Arrays.asList(1186568191955804162L, 1186561629153402882L);int ids = userMapper.deleteBatchIds(list);System.out.println(ids);}

(4)deleteByLambdaQueryWrapper

 @Testpublic void deleteByWrappersLamdba(){LambdaQueryWrapper<User> lambdaQueryWrapper = Wrappers.<User>lambdaQuery();lambdaQueryWrapper.eq(User::getAge,33).eq(User::getEmail,"xn@baomidou.com");int delete = userMapper.delete(lambdaQueryWrapper);System.out.println("删除记录:"+delete);}

(5)deleteByQueryWrapper

    @Testpublic void deleteByWrapper2(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.eq("age",23).eq("name","向中");int delete = userMapper.delete(queryWrapper);System.out.println("删除记录数:"+delete);}

MP的增删改查基本操作相关推荐

  1. Django 07. django框架模型之增删改查基本操作

    简介 django框架模型之数据库表增删改查基本操作 1. 生成数据库表结构         models.py #!/usr/bin/env python # -*- coding: utf-8 - ...

  2. mysql增删改查基本操作

    mysql创建(用户)表 DROP TABLE if `base_member` ; CREATE TABLE `base_member` (`id` int(11) NOT NULL AUTO_IN ...

  3. C#通过VS连接MySQL数据库实现增删改查基本操作

    创建一个数据库wsq 里面有一张beyondyanyu表 表里面有id(int).names(varchar).count(int).passwords(varchar) 数据可以自己添 1.导入My ...

  4. 【MongoDB】增删改查基本操作

    查看所有数据库 show dbs 切换数据库(若不存在,会自动创建) use databasename 删除当前数据库 db.dropDatabase() MongoDB中没有表,只有集合. 插入集合 ...

  5. h2数据库增删改查基本操作

    文章目录 1 基础增删查改代码实践 2 代码启动h2数据库和初始化 1 基础增删查改代码实践 通过jdbc的连接方式,对server模式的h2数据库进行增删查改操作 public static voi ...

  6. ios Sqlite数据库增删改查基本操作

    2019独角兽企业重金招聘Python工程师标准>>> 研究了几天的数据库,终于把它给搞出来了.Sqlite是ios上最常用的数据库之一,大家还是有必要了解一下的.这是仿照网上的一个 ...

  7. pymongo 增删改查基本操作汇总(基本)

    mongo_conn = mongo['user'] 1.查询 a.查询所有:mongo_conn.find({}) b.单条记录查询:mongo_conn.find_one({'name': 'Mi ...

  8. 数据库及数据库表的增删改查基本操作

    一.创建数据库 1.创建一个数据库名字为DB_sidamingzhu create database 数据库名称: mysql> create database DB_sidamingzhu; ...

  9. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十八)ES6.2.2 增删改查基本操作

    #文档元数据 一个文档不仅仅包含它的数据 ,也包含 元数据 -- 有关 文档的信息. 三个必须的元数据元素如下: ## _index     文档在哪存放 ## _type     文档表示的对象类别 ...

最新文章

  1. 为什么世界上一些最好的科学家和程序员,在世人眼里,都有点不太正常,甚至行为混乱...
  2. 【2040】反向输出序列
  3. 不使用 Maven 等构建工具,而使用原始方法在 IntelliJ IDEA 中整合 Tomcat 部署 Web 应用
  4. 2016 年开发者应该掌握的十个 Postgres 技巧
  5. Android原生框架--Xui使用
  6. 自制一款可搜索图片、设置页面背景的浏览器插件
  7. python输入个人所得税计算_Python实现的个人所得税计算器示例
  8. matlab字符识别ocr,OCR字符识别 matlab
  9. ajax的readystate为3,为什么在做ajax时无法获得readyState 3(why can't get readyState 3 when doing a ajax)...
  10. VUE + ONLYOFFICE
  11. 昆特牌显示无法连接至服务器,巫师之昆特牌总是显示无法连接网络
  12. 代码翻译尝试-使用Roaster解析和生成Java源码
  13. dp模式是什么意思_DP的完整形式是什么?
  14. 互联网+国家战略-整理
  15. go build解决missing go.sum.entry
  16. 解决H5播放视频黑屏只有声音没有图像的问题,Java调用ffmpeg转码成h264的mp4格式
  17. US Credit repay
  18. Eboot之函数BootloaderMain函数分析
  19. centos7-汉化vim帮助指令文档
  20. java开发的岗位职责,写给正在求职的Java开发

热门文章

  1. 25、软件安全-预防账号密码泄露
  2. 北斗导航 | 基于性能导航(PBN)涉及术语
  3. 万字长文科普:什么是低代码?
  4. puking java_GitHub - pukingli/mpsdk4j: JAVA微信公平台开发SDK,没有复杂的功能,一切源于微信API,愿你会喜欢使用。...
  5. 别再回头看了,往后的日子都是崭新的(创作纪念日)
  6. 工作效率提升技巧三:做事的心态
  7. mlag 堆叠_华为CE交换机M-LAG配置
  8. 不属于rh2285服务器运行电磁环境条件,传输设备-L1-L2试题
  9. 流量决定生意:什么是公域流量、什么是私域流量、什么是商域流量?三者结合,私域聚拢!...
  10. 客厅装修应注意空间的布局