Mybatis-plus查询常用记录

文章展示了如何在Java中进行SQL排序,如使用wrapper排序和StreamAPI对列表进行排序。此外,还演示了如何将结果转换为Map并处理重复项,以及将列表转换为集合。最后,文章提到了如何用Java编写SQL查询,包括条件过滤、分组和计数操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.sql排序

wrapper.last("ORDER BY sort DESC LIMIT 1");

或者

wrapper.orderByDesc(CheckFormItemDomain::getId);

2.结果排序

list.stream().sorted(Comparator.comparing(DataValueIntDTO::getValue).reversed()).collect(Collectors.toList());

3.结果转map

Map<Long, ChannelDomain> channelMap = channelList.stream().collect(Collectors.toMap(ChannelDomain::getId, Function.identity()));

处理重复

captainList.stream().collect(Collectors.toMap(FirehouseMicroMemberDomain::getMicroId, Function.identity(), (key1, key2) -> key2));

4.结果转集合

Set<Long> ids = new HashSet<>(domainList.stream().map(obj -> obj.getAccountSubjectId()).collect(Collectors.toList()));

5.结果循环

reqList.stream().forEach(req ->{
            CfgSimplePo po = new CfgSimplePo();
            po.setId(req.getId());
            po.setSort(req.getSort());
            list.add(po);
        });

6.java写sql

QueryWrapper<UnitDeviceShieldDomain> shieldWrapper = new QueryWrapper<UnitDeviceShieldDomain>();
        shieldWrapper.select("shield_type_dcode as type,COUNT(*) as cnt");
        shieldWrapper.eq(StringUtils.isNotBlank(streetId), "unit_street", streetId);
        shieldWrapper.eq(unitId != null, "unit_id", unitId);
        shieldWrapper.between(!requestDTO.getDateQueryCategory().equals(-1),
                "create_dtime", requestDTO.getStartTime(), requestDTO.getEndTime());
        shieldWrapper.groupBy("shield_type_dcode");
        List<Map<String, Object>> maps = unitDeviceShieldService.listMaps(shieldWrapper);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值