提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 前言
- AbstractWrapper 条件构造器
- 官网文档
- https://baomidou.com/pages/10c804/#abstractwrapper](https://baomidou.com/pages/10c804/#abstractwrapper)![在这里插入图片描述
- 案例
- allEq
- eq
- ne
- gt 、ge 、lt、le
- between 、notBetween
- like、notLike、likeLeft、likeRight、notLikeLeft、notlikeRight
- isNull、isNotNull
- in、notIn
- inSql、notInSql
- exists、notExists
- groupBy
- orderByAsc、orderByDesc、orderBy
- having
- func
- or
- and
- nested
- apply
- last
- QueryWrapper
- UpdateWrapper
前言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
AbstractWrapper 条件构造器
官网文档
https://baomidou.com/pages/10c804/#abstractwrapper
案例
@Testpublic void testSelect01(){List<User> userList = userDao.selectList(null);System.out.println(userList);}/*** 业务: 查询id=11的用户信息 主键...*/@Testpublic void testSelect02(){User user = userDao.selectById(11);System.out.println(user);}/*** 业务: 查询name属性为"小乔"的数据* sql: select * from user where name="小乔";* 对象的方式 > sql方式*/@Testpublic void testSelect03(){//条件构造器QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.eq("name", "小乔");List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 业务: 查询name属性为"小乔"的数据 并且 age >=18岁* sql: select * from user where name="小乔" and age>=18;** 大于 > gt| 小于 < lt |* 大于等于 >= ge | 小于等于 le*/@Testpublic void testSelect04(){//条件构造器QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.eq("name", "小乔").ge("age", 18);List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 业务: 查询name中包含 "精"的用户,并且sex为女* 业务: 查询name中包含 以精结尾的数据,并且sex为女* sql: select * from user where name like "%精%" and sex="女";*/@Testpublic void testSelect05(){//条件构造器QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.likeLeft("name", "精").eq("sex", "女");List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 需求: 查询user表中的数据 要求按照年龄降序排列,如果年龄相同按照id降序排列*/@Testpublic void testSelect06(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.orderByDesc("age","id");List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 需求: 查询name属性为null的数据.* where name is null*/@Testpublic void testSelect07(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.isNull("name");List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 查询name="小乔" age=17 性别=女的用户* 如果传递的是对象.会根据对象中不为null的属性充当where条件.*/@Testpublic void testSelect08(){User user = new User();user.setName("小乔").setAge(17).setSex("女");QueryWrapper<User> queryWrapper = new QueryWrapper<>(user);List<User> userList = userDao.selectList(queryWrapper);System.out.println(userList);}/*** 查询id=1,3,5,10数据.* sql: select * from user where id in (1,3,5,10)*/@Testpublic void testSelect09(){//转化时,注意使用对象的类型Integer[] ids = {1,3,5,10};List<Integer> idList = Arrays.asList(ids);List<User> userList = userDao.selectBatchIds(idList);System.out.println(userList);}@Testpublic void testInsert(){User user = new User();user.setName("特朗普").setAge(70).setSex("男");userDao.insert(user);}
allEq
eq
ne
gt 、ge 、lt、le
between 、notBetween
like、notLike、likeLeft、likeRight、notLikeLeft、notlikeRight
isNull、isNotNull
in、notIn
inSql、notInSql
exists、notExists
groupBy
orderByAsc、orderByDesc、orderBy
having
func
or
and
nested
apply
last
QueryWrapper
UpdateWrapper