2019-08-02

2019-08-02  本文已影响0人  艾特艾特艾特

以下问题安装sonarLint可以绝大部分避免!

        //错误示列
        Integer a1 = 128;
        Integer a2 = 128;
        System.out.println(a1 == a2);
        //正确示列
        Integer a3 = 128;
        Integer a4 = 128;
        System.out.println(Objects.equals(a3,a4));
Assert.notNull('执行判断的变量','要抛出的错误内容');
        //错误示列
        List<Long>  ids = new ArrayList<>();
        ids.forEach(id->{
            investigateHeaderRepository.selectByPrimaryKey(id);
        });
        //正确示列
        investigateHeaderRepository.selectByIds(ids.stream().map(Objects::toString).collect(Collectors.joining(",")));
   <resultMap id="test" type="头路径">
        <!--头字段信息
        .......
        -->
        <!--行映射 -->
        <collection property="属性名称" ofType="行路径"
                    javaType="type">
           <!-- 行字段信息
            ....
            -->
        </collection>
    </resultMap>
Map<String, String> reportMap = new HashMap<>(BaseConstants.Digital.TWO);
从源码分析中可以得知hash map 的扩容机制如果在最开始就指定hash map 的大小可以避免其底层不断的扩容
       @Test
    public void test(Integer a ) {
        int b;
        if (a==null){
            b=1;
        }else {
            b=2;
        }
        b = ObjectUtils.isEmpty(a) ? 1 : 2;
    }
 List<Integer> investigateTmplate = prices.stream().map(PriceDTO::getId).distinct().collect(Collectors.toList());
 
 //性能差距和第一种方式较为明显提升
 Set<Integer> collect = prices.stream().map(PriceDTO::getId).distinct().collect(Collectors.toSet());
        for (int i = 0; i < prices.size(); i++) 
        //可以避免循环中去获取size 
        int size = prices.size();
        for (int i = 0; i < size; i++) { }
如services调用实体里写的某一个方法而这个方法里没去避免并发调用出现的问题,也请慎用synchronized
    /**
     * 批量确定并发布调查表
     * @param tenantId              租户ID
     * @param investigateHeaderList 调查表头
     * @return 调查表头
     */
    List<InvestigateHeader> batchSaveAndReleaseInvestigate(Long tenantId,List<InvestigateHeader> investigateHeaderList);
 args.put(FIELD_ORGANIZATION_ID, investigateHeader.getPartnerTenantId() + "");
一段dml 不能落下事物,在必要时要注意事物的传播行为!

spring中this调用的事物会存在失效,因JDK的动态代理,在SpringIoC容器中返回的调用的对象是代理对象而不是真实的对象,只有被动态代理直接调用的才会产生事务。
可以去实现AopProxy来解决此类问题 然后改成this.self().方法()其底层原理为获取this对象的动态代理对象!
上一篇 下一篇

猜你喜欢

热点阅读