zoukankan      html  css  js  c++  java
  • mybatis与stream使用小记

    1-mybatis解决limit语句限制

    This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery异常解决方法

    例子1:mybatis-plus 1层子查询嵌套,mysql不支持LIMIT/IN/ANY/SOME

    // 查询最近100条数据
    List<SendNsqMessageDO> allfeeYopProtocolDTOs = sendNsqMessageMapper.selectList(
    new QueryWrapper<SendNsqMessageDO>()
    .inSql("id","select id from send_nsq_message order by created_at desc limit 100")
    );

    解决办法:2层子查询

    // 查询最近100条数据
    List<SendNsqMessageDO> allfeeYopProtocolDTOs = sendNsqMessageMapper.selectList(
    new QueryWrapper<SendNsqMessageDO>()
    .inSql("id","select t.id from (select * from send_nsq_message order by created_at desc limit 100) as t")
    );

    2-stream快速实现求和

    目的:结合mybatis查询结果,快速求和

     

    普通解决办法:求出列的List,然后遍历相加,求和

     

    简化版:

    int oweQuotaSum = alldebtRecords.stream().mapToInt(t->Math.toIntExact(t.getOweQuota())).sum();
    int oweQuotaSnapshotSum = alldebtRecords.stream().mapToInt(t->Math.toIntExact(t.getOweQuotaSnapshot())).sum();
    int recoveryQuotaSum = alldebtRecords.stream().mapToInt(t->Math.toIntExact(t.getRecoveryQuota())).sum();

  • 相关阅读:
    [go]go addressable 详解
    [go]灵活的处理json与go结构体
    [django]django内置的用户模型
    [go]文件读写&io操作
    *2.3.2_加入env
    UVM_INFO
    uvm_config_db在UVM验证环境中的应用
    *2.2.4 加入virtual interface
    *2.2.3 加入objection机制
    2.2.2 加入factory机制
  • 原文地址:https://www.cnblogs.com/forfreewill/p/13567070.html
Copyright © 2011-2022 走看看