当前位置:网站首页>【code】偶尔取值、判空、查表、验证等
【code】偶尔取值、判空、查表、验证等
2022-07-03 06:30:00 【掘金者说】
想了想还是记录一下,后续不断补充,方便后续查阅
获取List<String>
// 获取表IDs去重
List<String> tIds = list.stream()
.map(TableColumn::getTableParentId)
.distinct()
.collect(Collectors.toList());
// 获取表IDs
List<String> tIds = tables.stream()
.map(Table::getId)
.collect(Collectors.toList());
// 使用List<Map> 大小写注意
List<String> ids = params.stream()
.map(e -> e.get("id"))
.collect(Collectors.toList());
// 获取Parameter.getCheckFormat
List<CheckFormat> checkFormat = Optional.ofNullable(parameter)
.map(u -> u.getCheckFormat())
.orElse(new ArrayList<>());
// 获取最大
FieldConfig maxFieldConfig = configs.stream()
.max(Comparator.comparing(FieldConfig::getOrderId))
.orElse(null);
判断参数
// 判断:类型
if (type == null || !Arrays.asList("40", "60", "80").contains(type)) {
String msg = "选择参数类型 40.库 60.表 80.字段";
return TableUtil.getInstance().errorReturn(code, msg, msg);
}
// 判断:使用List<Map>,if(list != null && list.size() > 0) ===》》 CollectionUtils.isNotEmpty(list);
if (CollectionUtils.isEmpty(ruleList)) {
String msg = "未找到到规则";
return apiErrorReturn(500, msg, msg);
}
表查询
// 修改
LambdaUpdateWrapper<Dir> dirUpdate = Wrappers.lambdaUpdate();
dirUpdate.set(Dir::getName, source.getCnName());
dirUpdate.eq(Dir::getType, 13);
dirUpdate.eq(Dir::getCode, source.getCode());
directoryMapper.update(new SsDir(), dirUpdate);
// 查询
List<Integer> ids = params.stream().map(QuotaBO::getId).collect(Collectors.toList());
LambdaQueryWrapper<QuotaBO> queryQuota = Wrappers.lambdaQuery();
queryQuota.eq(QuotaBO::getIsDelete, 0);
queryQuota.in(QuotaBO::getId, ids);
List<QuotaBO> quotaList = quotaMapper.getList(queryQuota);
// 查询
QueryWrapper qw = new QueryWrapper<>();
qw.eq("COLUMN_NAME", columnName);
List<ColumnBO> list = colService.getListByPage(qw, pIndex, pSize);
// 修改
UpdateWrapper<ColumnBO> uw = new UpdateWrapper<>();
uw.eq("ID", column.getId());
List<ColumnBO> list = colService.getListByPage(column, uw);
数据去重
// 使用id去重处理
bloodList = bloodList.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(()
-> new TreeSet<>(Comparator.comparing(BloodBO::getId))), ArrayList::new));
验证是否存在
有数据时候就不要重复添加数据,在验证该数据是否已存在时候,需要考虑新增、修改(修改时候需要忽略本身已存在条件)
select count(1) as valid, concat('分类编号【' ,#{itemId}, '】已存在') as message from pig_item
where IS_DELETE = 0
and ITEM_ID = #{itemId}
and (ID != #{idOld} or #{idOld} is null)
<select id="checkVerifyItemNum" resultType="java.lang.Integer">
<![CDATA[ select count(1) as valid from pig_item where IS_DELETE=0 and ITEM_ID = #{itemId} ]]>
<if test="id != null">
<![CDATA[ and (ID != #{id} or #{id} is null) ]]>
</if>
</select>
<![CDATA[ 内容 ]]>
这个写法好处就是大于小于就不要转义,不方便的是判断条件时候就要分开写
多表查询
多张表查询,left join下去,数据是有了,当数据量多了以后,查询性能降低.
with tmp_tab as (
select 先查询数据
),
tmp_desc as (
select 再查询数据
) select * from tmp_desc
边栏推荐
- 【无标题】8 简易版通讯录
- IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
- Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
- Simple password lock
- Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
- Luogu problem list: [mathematics 1] basic mathematics problems
- Know flex box
- POI dealing with Excel learning
- The most classic 100 sentences in the world famous works
- How to scan when Canon c3120l is a network shared printer
猜你喜欢
Ruoyi interface permission verification
2022年华东师范大学计科考研复试机试题-详细题解
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
Project summary --2 (basic use of jsup)
【系统设计】邻近服务
Kubesphere - build Nacos cluster
Important knowledge points of redis
ROS+Pytorch的联合使用示例(语义分割)
使用conda创建自己的深度学习环境
随机推荐
Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
Yolov1 learning notes
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
Learning notes -- principles and comparison of k-d tree and IKD tree
【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
Phpstudy setting items can be accessed by other computers on the LAN
DNS forward query:
Advanced technology management - do you know the whole picture of growth?
POI dealing with Excel learning
SQL implementation merges multiple rows of records into one row
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
A letter to graduating college students
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
远端rostopic的本地rviz调用及显示
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
ROS+Pytorch的联合使用示例(语义分割)
How to scan when Canon c3120l is a network shared printer
Redis cluster creation, capacity expansion and capacity reduction
Numerical method for solving optimal control problem (I) -- gradient method