1 集合快速分组

  1. List<List<EcontResourcesDto>> partition = com.google.common.collect.Lists.partition(list, 20);
  2. 集合快速拆分; 每组20调数据
  3. guava的依赖
  4. <dependency>
  5. <groupId>com.google.guava</groupId>
  6. <artifactId>guava</artifactId>
  7. <version>28.0-jre</version>
  8. </dependency>

2 方法返回两个返回值

  1. <dependency>
  2. <groupId>org.apache.commons</groupId>
  3. <artifactId>commons-lang3</artifactId>
  4. <version>3.11</version>
  5. </dependency>
  6. MutablePair<String, String> mutablePair = MutablePair.of("1", "第二个值");
  7. System.out.println(mutablePair.getLeft() + "," + mutablePair.getRight());

3 方法返回三个返回值

  1. <dependency>
  2. <groupId>org.apache.commons</groupId>
  3. <artifactId>commons-lang3</artifactId>
  4. <version>3.11</version>
  5. </dependency>
  6. MutableTriple<Integer, String, Date> mutableTriple = MutableTriple.of(2, "中间值", new Date());
  7. System.out.println(mutableTriple.getLeft() + "," + mutableTriple.getMiddle() + "," + mutableTriple.getRight());

4 事物方法模拟回退、回滚、异常

  1. // // binc_rollback 实验代码稍后删除 模拟这里发生异常,看看能否回退
  2. int i = 1;
  3. int j = 1;
  4. if (i-j == 0){
  5. throw BusinessRtException.of("------------------------------------------------------" +
  6. "---------------------------------------------------------------------------------" +
  7. "-----------------------------------模拟发生异常,强制数据库执行回退---------------------------------------------" +
  8. "---------------------------------------------------------------------------------" +
  9. "--------------------------------------------------------------");
  10. }

5 mapper.xml 默认值问题

  1. <if test="item.state != null">
  2. #{state} ,
  3. </if>
  4. <if test="item.state == null">
  5. 1 ,
  6. </if>

6 string 一些操作

StringUtils.hasText(字符串) 里面的值为  null  、""   、 "  ",

那么返回值为false,否则为true

7 option

            accountsRefundDto.setTradeStatus(Optional.ofNullable(accountVo).map(o -> Optional.ofNullable(o.getPayStatus()).orElse(FundAccountFlowConstants.TRADE_STATUS_FAIL)).orElse(FundAccountFlowConstants.TRADE_STATUS_FAIL));


data.stream()
    .filter(d -> Objects.equals(d.getOrgLevelId(), f.getBranchId()))
    .findFirst()
    .ifPresent(p -> {
        f.setBranchName(p.getOrgLevelName());
    });