Mybatis-plus中QueryWrapper的使用
一、QueryWrapper是什么?
QueryWrapper就是在使用Mybatis-plus中真实用到的一种技术,也叫作构造器,能简化sql的操作。
二、常用方法总结
1、单表操作
代码如下(示例):我要查询姓名、班级、年龄符合前端传过来参数的数据并进行排序。
@GetMapping("/list")
public TableDataInfo list(Student student){LambdaQueryWrapper<Student> lqw = new LambdaQueryWrapper<Student>();lqw.eq(Student::getName, student.getName());lqw.like(Student::getClass,student.getClass());lqw.between("age",student.getAge1(),student.getAge2());lqw.orderByAsc("age");List<Student> list = studentService.list(lqw);
}
以上代码对应的sql为:
select * from student where name = '?' and class like '%?%' and age between '?' and '?' order by '?' asc
由此可以看出,QueryWrapper其实可以理解成一个放查询条件的盒子,我们把查询条件放在里面,他就会自动按照对应的条件进行查询数据。
根据不同的查询要求,有不同的用法,常用到的比如:eq、like、and、or、isNull、isNotNull、ne、likeRight、between等;使用方法及说明见下图。
2、多表操作
//Controller
@GetMapping("/listAndClass")
public TableDataInfo listAndClass(Student student)
{QueryWrapper<Student > qw = new QueryWrapper<Student >();if(StringUtils.isNotBlank(student.getName())){qw.eq("s.name",student.getName());}if(StringUtils.isNotBlank(student.getClassName())){qw.like("c.name",student.getClassName());}startPage();List<Student > list = studentService.listAndClass(qw);return getDataTable(list);
}//ServiceList<Student> listAndClass(QueryWrapper<Student> qw);//Service impl
@Override
public List<Student> listAndClass(QueryWrapper<Student> qw) {return this.getBaseMapper().listAndClass(qw);
}//Mapper
@Select("select s.*,c.name from student s left join class c on s.id = c.student_id "+"${ew.customSqlSegment}")
List<YwSpaqjgDj> listAndClass(@Param(Constants.WRAPPER) QueryWrapper<Student> qw);
Mybatis-plus中QueryWrapper的使用相关推荐
- mybatis框架中的queryWrapper的or查询,联想到MySQL中and 和or的关系
统计的原生SQL应该是这样的: SELECTCOUNT( 1 ) FROMtable_name WHERE( id = '679135XXXXXXX1212' AND ( STATUS = 1 OR ...
- mybatis XML 中<if>、<choose>、<when>、<otherwise>等标签的使用?多条件查询该怎么处理?
mybatis XML 中if.choose.when.otherwise等标签的使用 一般使用在多条查询,虽然也可以通过注解写,我比较菜,我不会. 一般多条查询怎么解决? 1.如果是单表间的多条件查 ...
- MyBatis之优化MyBatis配置文件中的配置
MyBatis之优化MyBatis配置文件中的配置 2017/9/30 MyBatis配置文件很重要,首先我们来看看MyBatis配置文件中的内容和顺序: 文件目录结构如下: 1.<proper ...
- mybatis 配置文件中,collection 和 association 的对应关系
mybatis 配置文件中,collection 和 association 的对应关系 如下图所示:
- ❤️Mybatis开发中什么是多对一处理、一对多处理?
❤️Mybatis开发中什么是多对一处理.一对多处理? 什么是多对一: 对于学生而言,关联-多个学生关联一个老师(多对一) 对于老师而言,集合-一个老师有很多学生(一对多) SQL: CREATE T ...
- Mybatis xml中配置一对一关系association一对多关系collection
Mybatis xml中配置一对一关系association&一对多关系collection 今天在配置一对一关系映射以及一对多关系映射的时候,把collection中应该使用的ofType配 ...
- Mybatis.xml中sql语句的转译
Mybatis.xml中sql语句的转译
- mybatis接口中的方法重载_MyBatis的Mapper接口以及Example的实例函数及详解
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- mybatis plus 中 EntityWrapper源码解读
mybatis plus内置了好多CRUD,其中 EntityWrapper这个类就是. 这个类是mybatis plus帮我们写好的好多接口,就如同我们在dao层写好方法在xml中实现一样. 那么这 ...
- mybatis 配置文件中set丢失逗号
实例代码 <update id="updateSelective" parameterType="apply">UPDATE apply<se ...
最新文章
- 字符串拆分-Java
- OS / Linux / clone、fork、vfork 与 pthread_create 创建线程有何不同
- github使用-知乎的某小姐的一篇文章
- C++ 中不能被继承的类实现,及从中体现virtual 继承的一个特性
- UVA1343 The Rotation Game旋转游戏
- iOS里面MVC模式详解
- Unity面试题精选(1)
- 暴雪准备用AI打击“游戏喷子”
- Jquery 判断IE
- STM32H743 驱动 W25Q256
- 阿里云DataV数据可视化---数据
- (9)数据分析-相关性分析
- php项目代做,代做PHP开发技术程序、php网站代码代写
- 万科的管理层为何要在质疑中坚定地推迟董事会改选?
- 【更新中21/31】NTIRE 2022 ESR(efficient super-resolution) 方案与结果
- HTNL常见的标签及属性 和w3school的使用
- 项目管理中的冲突管理
- Cannot run program jad
- Charles抓包工具使用介绍
- 计算机常用名词及解释
热门文章
- 中国象棋python实现(拥有完整源代码) Alpha-beta剪枝+GUI+历史启发式+有普通人棋力
- VVIC api接口
- java整合消息推送_SpringMVC整合websocket实现消息推送及触发功能
- 腾讯会议如何退款,如何重新购买
- Phonetic symbol 双元音 -- əʊ
- 线性稳压器的基本类型
- 爬取百度贴吧图片-python-requests
- 模拟火车站售票窗口,开启三个窗口售票,总票数为100张
- R pdf大小_全能格式转换工具分享,PDF 转 Word、视频图片格式转换等
- 改变PPT导出图片分辨率