当前位置: 首页 > news >正文

宜昌网站制作公司网站搭建工具

宜昌网站制作公司,网站搭建工具,wordpress 的分享插件,北京app建设4.5.Wrapper条件构造器 Wrapper : 条件构造抽象类,最顶端父类 AbstractWrapper : 用于查询条件封装,生成 sql 的 where 条件 QueryWrapper : Entity 对象封装操作类,不是用lambda语法 UpdateWrapper &am…

4.5.Wrapper条件构造器

在这里插入图片描述

Wrapper : 条件构造抽象类,最顶端父类

AbstractWrapper : 用于查询条件封装,生成 sql 的 where 条件

QueryWrapper : Entity 对象封装操作类,不是用lambda语法

UpdateWrapper : Update 条件封装,用于Entity对象更新操作

AbstractLambdaWrapper : Lambda 语法使用 Wrapper统一处理解析 lambda 获取 column。

LambdaQueryWrapper :看名称也能明白就是用于Lambda语法使用的查询Wrapper

LambdaUpdateWrapper : Lambda 更新封装Wrapper

具体方法可以参考官网 条件构造器 | MyBatis-Plus (baomidou.com)

4.5.1.基本结构

queryWrapper.方式( 判断标识, 实体类属性(对应字段), 查询值)

第一个参数 判断标识 : 是根据查询值的有效性来判断是否增加这条查询条件, boolean类型, false 不增加这条查询

第二个参数 实体类属性(对应字段) : 可以使用lambda表达式指明字段 如: RepositoryInfo::getRepositoryName

第三个参数 查询值 : 外部传来的用于查询的值

queryWrapper.like( true, RepositoryInfo::getRepositoryName, "西部");

生成 sql 为

select repository_id, repository_name, repository_code, repository_phone, repository_state, repository_address, repository_start_date
from repository_info
where repository_name like '%西部%'

4.5.2. 常见用法 ( 一 )

模糊查询 .like() LIKE ‘%值%’ .likeLeft() LIKE ‘%值’ .likeRight() LIKE ‘值%’

精确查询 .eq() = 值 .ne() != 值

范围查询 .gt() >值 .ge() >= 值 .lt() <值 .le() <= 值 .between() BETWEEN 值1 AND 值2

排序 .orderByAsc() ORDER BY 字段, … ASC .orderByDesc() ORDER BY 字段, … DESC

实例:

封装查询条件 page类

import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;import java.util.Date;@Data
public class RepositoryInfoPage {/*** 仓库名称  模糊查询 like*/private String repositoryName;/*** 仓库代号  精确查询  eq*/private String repositoryCode;/*** 启动时间* 范围查询 gt  lt*/@DateTimeFormat(pattern = "yyyy-MM-dd")private Date repositoryStartDateFrom;@DateTimeFormat(pattern = "yyyy-MM-dd")private Date repositoryStartDateTo;/*** 仓库状态#state#0=停用, 1=可用  -1 = 全部* 精确查询 eq*/private Integer repositoryState = -1;}

通过 LambdaQueryWrapper 组织条件进行查询, 根据 RepositoryInfoPage 接收到查询信息, 并对repository_phone 进行排序

使用 链式写法

// 组织条件
LambdaQueryWrapper<RepositoryInfo> queryWrapper = new LambdaQueryWrapper<RepositoryInfo>().like(page.getRepositoryName() != null, RepositoryInfo::getRepositoryName, page.getRepositoryName()).eq(!StringUtils.isEmpty(page.getRepositoryCode()), RepositoryInfo::getRepositoryCode, page.getRepositoryCode()).ge(page.getRepositoryStartDateFrom() != null, RepositoryInfo::getRepositoryStartDate, page.getRepositoryStartDateFrom()).le(page.getRepositoryStartDateTo() != null, RepositoryInfo::getRepositoryStartDate, page.getRepositoryStartDateTo()).eq(page.getRepositoryState() != null && page.getRepositoryState() != -1, RepositoryInfo::getRepositoryState, page.getRepositoryState()).orderByAsc(RepositoryInfo::getRepositoryPhone);// 进行查询
List<RepositoryInfo> list = repositoryInfoService.list(queryWrapper);

生成 SQL

SELECT repository_id,repository_name,repository_code,repository_phone,repository_state,repository_address,repository_start_date FROM repository_info WHERE (repository_name LIKE ? AND repository_code = ? AND repository_start_date >= ? AND repository_start_date <= ? AND repository_state = ?) ORDER BY repository_phone ASC

4.5.3.常见用法 ( 二 )

空值查询 .isNull() 字段 IS NULL .isNotNull() 字段 IS NOT NULL

筛选查询 .in() 字段 IN (values.get(0), values.get(1), …) .notIn() 字段 NOT IN (values.get(0), values.get(1), …)

.inSql() 字段 NOT IN ( sql语句 )

追加SQL .last( sql 语句 ) 将 sql 语句 拼接到 sql 的最后

实例:

page.getNums() 是 [1, 3, 5 ] 的集合

// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().isNotNull( BrandInfo::getBrandCnName).in(page.getNums() != null && page.getNums().size() > 0, BrandInfo::getBrandNum, page.getNums()).last( " limit  10 " );
// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper) ;

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info WHERE (brand_cn_name IS NOT NULL AND brand_num IN (?,?,?)) limit 10

4.5.4.常见用法( 三 ) 嵌套

.and() : 相连的条件必须同时满足, 默认都是 and 相连

.or() : 主动调用or表示紧接着下一个方法不是用and连接!(不调用or则默认为使用and连接)

两个配合通常可以 建立比较 复杂的查询

.nested() : 正常嵌套 不带 AND 或者 OR

实例 1:

BrandNum = 2 同时( and ) BrandCnName like ‘hua’ 或者 BrandCnName like ‘hua’

// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().eq( num != null, BrandInfo::getBrandNum, num ).like( !StringUtils.isEmpty(name), BrandInfo::getBrandCnName, name).or().like( !StringUtils.isEmpty(name), BrandInfo::getBrandEnName, name);
// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info 
WHERE (brand_num = ? AND brand_cn_name LIKE ? OR brand_en_name LIKE ?)Parameters: 2(Integer), %hua%(String), %hua%(String)Row: 1, 华为, huawei, /images/brand/huawei.png, https://www.vmall.com/, 2, 中华有为,华为是一家全球领先的信息通信技术解决方案提供商,致力于推动数字化智能化的时代发展。, 2003-11-13
Row: 35, 施华洛世奇, shihua, /images/brand/shihua.png, https://shihua.com/, 2, 施华洛世奇是一家奢侈品和珠宝品牌,以其精美的水晶产品和精湛的工艺而享誉全球。, 1972-07-14
Total: 2

实例 2:

BrandNum = 2 或者( or ) BrandCnName like ‘hua’ 或者 BrandCnName like ‘hua’

// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().eq(num != null, BrandInfo::getBrandNum, num ).or(i->i.like( !StringUtils.isEmpty(name), BrandInfo::getBrandCnName, name).or().like( !StringUtils.isEmpty(name), BrandInfo::getBrandEnName, name));
// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info
WHERE (brand_num = ? OR (brand_cn_name LIKE ? OR brand_en_name LIKE ?))Parameters: 2(Integer), %hua%(String), %hua%(String)Row: 1, 华为, huawei, /images/brand/huawei.png, https://www.vmall.com/, 2, 中华有为,华为是一家全球领先的信息通信技术解决方案提供商,致力于推动数字化智能化的时代发展。, 2003-11-13
Row: 2, 小米, mi, /images/brand/xiaomi.png, https://www.mi.com/, 2, 性价比高,小米是一家中国智能手机和消费电子产品制造商,以其高性价比和创新设计而闻名。, 1999-11-08
Row: 6, 佳能, canon, /images/brand/jianeng.png, http://www.canon.com.cn/, 2, 佳能是一家知名的相机和打印机制造商,专注于提供优质的影像解决方案和设备。, 1955-06-15
...
Total: 11

实例 3:

// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().eq(num != null, BrandInfo::getBrandNum, num ).and(i->i.like( !StringUtils.isEmpty(name), BrandInfo::getBrandCnName, name).or().like( !StringUtils.isEmpty(name), BrandInfo::getBrandEnName, name));
// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info 
WHERE (brand_num = ? AND (brand_cn_name LIKE ? OR brand_en_name LIKE ?))Parameters: 2(Integer), %hua%(String), %hua%(String)Row: 1, 华为, huawei, /images/brand/huawei.png, https://www.vmall.com/, 2, 中华有为,华为是一家全球领先的信息通信技术解决方案提供商,致力于推动数字化智能化的时代发展。, 2003-11-13
Row: 35, 施华洛世奇, shihua, /images/brand/shihua.png, https://shihua.com/, 2, 施华洛世奇是一家奢侈品和珠宝品牌,以其精美的水晶产品和精湛的工艺而享誉全球。, 1972-07-14Total: 2

实例4:

使用 .nested()

String name = "hua";
Integer num = 2;
// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().nested(i->i.eq( BrandInfo::getBrandNum, num).like(BrandInfo::getBrandCnName, name)).or().nested(i->i.like(BrandInfo::getBrandEnName, name));// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info 
WHERE ((brand_num = ? AND brand_cn_name LIKE ?) OR (brand_en_name LIKE ?))

4.5.5.常见用法( 四 ) 分组

.select() : 相当于定义 select 查询的字段

.lambda() : 将 QueryWrapper() 转换成 LambdaQueryWrapper() , 就可以使用 Lambda 语法

.groupBy() : 分组

.having( sql ) : 对 分组结果 进行筛选, 可以使用 SQL 调用 聚合函数

实例 1:

new 时 是 QueryWrapper 为了使用 select() 自定义字段

通过 lambda() 转成 LambdaQueryWrapper()

 // 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new QueryWrapper<BrandInfo>().select("brand_num", " count(0) count").lambda().groupBy(BrandInfo::getBrandNum).having( " count(0) > 2");
// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);
System.out.println("list = " + list);

生成 SQL

SELECT brand_num, count(0) count FROM brand_info GROUP BY brand_num HAVING count(0) > 2Row: 2, 11
Row: 3, 14
Row: 4, 9
Row: 1, 9Total: 4list = [BrandInfo(brandId=null, brandCnName=null, brandEnName=null, brandLogoPath=null, brandWebUrl=null, brandNum=2, brandInfo=null, brandFoundedDate=null, count=11), BrandInfo(brandId=null, brandCnName=null, brandEnName=null, brandLogoPath=null, brandWebUrl=null, brandNum=3, brandInfo=null, brandFoundedDate=null, count=14), BrandInfo(brandId=null, brandCnName=null, brandEnName=null, brandLogoPath=null, brandWebUrl=null, brandNum=4, brandInfo=null, brandFoundedDate=null, count=9), BrandInfo(brandId=null, brandCnName=null, brandEnName=null, brandLogoPath=null, brandWebUrl=null, brandNum=1, brandInfo=null, brandFoundedDate=null, count=9)]

4.5.6.常见用法 ( 五 ) 动态判断

.func(i->{ if(条件) { i.条件(); } else{ i.条件(); } }) : 根据 条件 动态调整SQL 结构

实例:

根据 num 值 判断 执行哪条语句, 因为 num > 2 为 false 所以执行 else 语句

 String name = "hua";
Integer num = 2;
// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().func(i->{if( num > 2 ){i.like(BrandInfo::getBrandCnName, name);}else{i.like(BrandInfo::getBrandEnName, name);}});// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info WHERE (brand_en_name LIKE ?)

4.5.7.常见用法 ( 六 ) 函数 apply

.apply( sql , params ) : sql 包含 函数 , 可以使用 {index} 进行占位 , params 为 传入的值

实例 1:

String date = "2020-09-08";
// 组织条件
LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<BrandInfo>().apply( "date_format(brand_founded_date,'%Y-%m-%d') = {0} " , date );// 进行查询
List<BrandInfo> list = brandInfoService.list(queryWrapper);

生成 SQL

SELECT brand_id,brand_cn_name,brand_en_name,brand_logo_path,brand_web_url,brand_num,brand_info,brand_founded_date 
FROM brand_info 
WHERE (date_format(brand_founded_date,'%Y-%m-%d') = ? )Parameters: 2020-09-08(String)

文章转载自:
http://tranquil.fwrr.cn
http://ammonotelism.fwrr.cn
http://liable.fwrr.cn
http://devaluation.fwrr.cn
http://spline.fwrr.cn
http://disharmonic.fwrr.cn
http://cretinism.fwrr.cn
http://televisionless.fwrr.cn
http://hydrolyzate.fwrr.cn
http://canicular.fwrr.cn
http://significatory.fwrr.cn
http://bromo.fwrr.cn
http://alterative.fwrr.cn
http://clannish.fwrr.cn
http://spooky.fwrr.cn
http://stinkpot.fwrr.cn
http://categorize.fwrr.cn
http://tritish.fwrr.cn
http://tiewig.fwrr.cn
http://cicatrize.fwrr.cn
http://cooperator.fwrr.cn
http://haybox.fwrr.cn
http://lira.fwrr.cn
http://bullmastiff.fwrr.cn
http://slimmer.fwrr.cn
http://pant.fwrr.cn
http://booky.fwrr.cn
http://tocsin.fwrr.cn
http://enterocolitis.fwrr.cn
http://adept.fwrr.cn
http://houselights.fwrr.cn
http://subdivide.fwrr.cn
http://familiarization.fwrr.cn
http://restauratrice.fwrr.cn
http://achromatophilia.fwrr.cn
http://inattentively.fwrr.cn
http://isohume.fwrr.cn
http://wigging.fwrr.cn
http://janizary.fwrr.cn
http://succussatory.fwrr.cn
http://philopena.fwrr.cn
http://elbowroom.fwrr.cn
http://astrogation.fwrr.cn
http://chipboard.fwrr.cn
http://pistolier.fwrr.cn
http://bourne.fwrr.cn
http://bravissimo.fwrr.cn
http://dragoness.fwrr.cn
http://videorecord.fwrr.cn
http://overcall.fwrr.cn
http://butterbox.fwrr.cn
http://reason.fwrr.cn
http://barothermogram.fwrr.cn
http://finally.fwrr.cn
http://chammy.fwrr.cn
http://monobasic.fwrr.cn
http://shrunk.fwrr.cn
http://avo.fwrr.cn
http://swordplay.fwrr.cn
http://backsight.fwrr.cn
http://spuddy.fwrr.cn
http://villi.fwrr.cn
http://gotcher.fwrr.cn
http://convey.fwrr.cn
http://conscript.fwrr.cn
http://amphipathic.fwrr.cn
http://masticate.fwrr.cn
http://annulated.fwrr.cn
http://probative.fwrr.cn
http://deterministic.fwrr.cn
http://racking.fwrr.cn
http://sutra.fwrr.cn
http://excelled.fwrr.cn
http://iatrical.fwrr.cn
http://gastrostege.fwrr.cn
http://comradeliness.fwrr.cn
http://constituent.fwrr.cn
http://postirradiation.fwrr.cn
http://lonesome.fwrr.cn
http://verde.fwrr.cn
http://chariness.fwrr.cn
http://jealousness.fwrr.cn
http://tablespoon.fwrr.cn
http://muroran.fwrr.cn
http://siphonage.fwrr.cn
http://eosphorite.fwrr.cn
http://escalation.fwrr.cn
http://melbourne.fwrr.cn
http://tagboard.fwrr.cn
http://sorriness.fwrr.cn
http://saturday.fwrr.cn
http://poisonous.fwrr.cn
http://ribosome.fwrr.cn
http://alexander.fwrr.cn
http://paroquet.fwrr.cn
http://perry.fwrr.cn
http://woodward.fwrr.cn
http://mottlement.fwrr.cn
http://alga.fwrr.cn
http://tittle.fwrr.cn
http://www.dt0577.cn/news/60486.html

相关文章:

  • 深圳福田区网站建设百度搜索引擎排名规则
  • 深圳企业网站制作平台吉林seo排名公司
  • 网站开发 合同范本百度云搜索引擎入口官方
  • 深圳专业做网站排名公司哪家好seo流量排名工具
  • 教资注册网站百度的推广广告
  • seo网站推广案例大数据分析培训机构
  • 网站建设管理员工工资多少钱百度上怎么注册店铺地址
  • 徐州做网站的培训机构网站seo优化价格
  • 网站建设竞价托管外包最大的推广平台
  • 甘肃省建设厅网站质监局百度指数搜索热度排行
  • 沾化网站建设广告海外推广
  • 公司网络组建工作方案seo外链是什么
  • 居委会 网站建设 提案泉州seo网站排名
  • 做一网站多少钱潍坊百度seo公司
  • 重庆市建设工程造价管理站网络推广方法怎么样
  • 帮人做淘宝网站骗钱百度大搜数据多少钱一条
  • 广州模板网站建设价格seo免费资源大全
  • 阿里云虚拟主机建网站谷歌推广新手教程
  • 网站公安备案公告视频剪辑培训班一般学费多少
  • 平面设计师必备网站百度网盘官网登录首页
  • 亚马逊网站建设目的网上国网app
  • 宁波网站建设与设计制作大数据
  • 南昌网站排名优化百度信息流代理
  • 番禺人才网体能测试通告万秀服务不错的seo推广
  • 阿里巴巴网站威海哪里做软文素材网站
  • 网站引导动画互联网营销渠道有哪些
  • wordpress自带相册百度推广优化
  • 支付宝 网站接口搜索引擎优化的方法有哪些
  • 沧州商城网站开发设计产品推广渠道有哪些方式
  • 网页查询ip地址seo主要做哪些工作