【引言】 使用mybatis-plus框架的基础上,直接使用其中的条件参数进行查询还是很方便的。但每次使用到像大于、不等于这样一些不常用条件时,都需要现查,所以记录在这篇博客里,当作一个自己的查询手册。 【手册】 【示例】 之前《Mybatis-Plus 3.X 条件查询》博客中,也写过一些查询的使用,下面总结几个其中没有提到的,使用的mybatis-plus版本是3.1.1。 代码使用: sql打印: 代码使用: sql打印: 代码使用: sql打印: 代码使用: sql打印: 代码使用: sql打印: 代码使用: sql打印:
查询方式
说明
select
设置查询字段
and
AND 语句,拼接 + AND (字段=值)
or
OR 语句,拼接 + OR (字段=值)
eq
等于=
allEq
基于 map 内容等于=
ne
不等于<>
gt
大于>
ge
大于等于>=
lt
小于<
le
小于等于<=
like
模糊查询
notLike
模糊查询 NOT LIKE
in
IN 查询
notIn
NOT IN 查询
isNull
NULL 值查询
isNotNull
IS NOT NULL
groupBy
分组 GROUP BY
having
HAVING 关键词
orderBy
排序 ORDER BY
orderAsc
ASC 排序 ORDER BY
orderDesc
DESC 排序 ORDER BY
exists
EXISTS 条件语句
notExists
NOT EXISTS 条件语句
between
BETWEEN 条件语句
notBetween
NOT BETWEEN 条件语句
last
拼接在最后,例如:last(“LIMIT 1”)
//查询作者和编码字段,返回Article中其他字段的值均为null public Article searchOne(Integer id) { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.select(Article::getAuthor,Article::getCode).eq(Article::getId,id); return articleMapper.selectOne(queryWrapper); }
public List<Article> searchMore(String keywords) { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Article::getCatId,10); queryWrapper.and(x->x.like(Article::getKeywords,keywords).or().like(Article::getTitle,keywords)); return articleMapper.selectList(queryWrapper); }
//查询条件:访问量大于等于100 public List<Article> searchByCondition() { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); //大于等于 queryWrapper.ge(Article::getVisits,100); //查询指定字段 queryWrapper.select(Article::getAuthor,Article::getCode,Article::getTitle,Article::getVisits); return articleMapper.selectList(queryWrapper); }
//栏目Id属于10和20的 public List<Article> searchByCondition() { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); //in Long[] catId = {10L,20L}; List<Long> catList = Arrays.asList(catId); queryWrapper.in(Article::getCatId,catList); //查询指定字段 queryWrapper.select(Article::getAuthor,Article::getCode,Article::getTitle,Article::getVisits); return articleMapper.selectList(queryWrapper); }
//查询发布时间在2020-05-01至2020-06-25 public List<Article> searchByCondition() { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); //between queryWrapper.between(Article::getPublishTime, LocalDate.of(2020,5,1),LocalDate.now().plusMonths(1)); //查询指定字段 queryWrapper.select(Article::getAuthor,Article::getCode,Article::getTitle,Article::getVisits); return articleMapper.selectList(queryWrapper); }
//查询指定栏目下所有,并按访问量和创建时间排序 public List<Article> searchByCondition() { LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Article::getCatId,20); //查询指定字段 queryWrapper.select(Article::getAuthor,Article::getCode,Article::getTitle,Article::getVisits); //按访问量和创建时间排序 queryWrapper.orderByDesc(Article::getVisits).orderByAsc(Article::getCreateTime); return articleMapper.selectList(queryWrapper); }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算