小编Sah*_*bra的帖子

Kotlin Coroutines具有回归价值

我想创建一个具有返回值的协程方法.

例如)

fun funA() = async(CommonPool) {
    return 1
}

fun funB() = async(CommonPool) {
    return 2
}

fun sum() {
    launch {
        val total = funA().await() + funB().await()
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我想要求总和方法,我该怎么办?

喜欢,

fun sum(): Int {
    launch {
        val total = funA().await() + funB().await()
    }   

    return total
}
Run Code Online (Sandbox Code Playgroud)

kotlin kotlinx.coroutines

11
推荐指数
6
解决办法
1万
查看次数

在SpringBoot 2.1.x中使用RestTemplateBuilder的requestFactory的自定义RestTemplate与1.5.x版本不向后兼容

Spring Boot 1.5.x中,我正在创建RestTemplate如下的自定义:

@Bean
  public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
    poolingConnectionManager.setMaxTotal(restTemplateProps.getMaxConnectionsPerPool());
    poolingConnectionManager.setDefaultMaxPerRoute(restTemplateProps.getMaxDefaultConnectionPerRoute());
    CloseableHttpClient client = HttpClientBuilder.create().setConnectionManager(poolingConnectionManager).build();
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
        new HttpComponentsClientHttpRequestFactory(client);
    clientHttpRequestFactory.setConnectTimeout(restTemplateProps.getConnectionTimeout());
    clientHttpRequestFactory.setReadTimeout(restTemplateProps.getSocketTimeout());
    return restTemplateBuilder.requestFactory(clientHttpRequestFactory).build();
  }
Run Code Online (Sandbox Code Playgroud)

但是,在迁移到Spring Boot 2.1.x之后,上面的代码无法编译。看起来好像requestFactoryHttpComponentsClientHttpRequestFactory作为输入参数。

谁能建议我如何在Spring Boot 2.1.x中实现以上代码?

java resttemplate spring-boot

8
推荐指数
3
解决办法
4765
查看次数

如何从日期获得零售(4-5-4)日历周

我需要得到,从一个日期4-5-4日历周.是否有像Java格鲁吉亚日历这样的实用程序用于4-5-4零售日历?如果没有,我该如何创建一个?需要什么逻辑?在闰年的情况下,第53周是什么时候?

例如,如果我传递一个日期(DD-MM-YYY)04-03-2018作为输入,我应该得到March Week 1输出.或者,如果我提供01-04-2018输入,我应该得到March Week 5输出.

请通过提供构建此实用程序的方法来帮助我.

java calendar

5
推荐指数
0
解决办法
525
查看次数

Kotlin协程的Jacoco代码覆盖率不正确

我正在使用Jacoco进行单元测试代码覆盖。Jacoco生成的报告显示,我的Kotlin代码几乎没有遗漏任何分支。我注意到协程代码,之后的代码根据Jacoco未被正确覆盖。我不确定这是因为协程或其他原因。使用IntelliJ代码覆盖率运行单元测试时,我的Kotlin类显示100%的覆盖率

我不知道为什么Jacoco的报道范围减少了。我已经使用Spock(Groovy)编写了单元测试。

请参考以下图片:

错过的分支: 在此处输入图片说明

在此处输入图片说明

原始代码: 在此处输入图片说明

code-coverage spock jacoco kotlin kotlinx.coroutines

5
推荐指数
1
解决办法
899
查看次数

使用 HttpComponentsClientHttpRequestFactory 在 RestTemplateBuilder 中添加自定义 ClientHttpRequestInterceptor

I need to add a Custom Header in all my RestTemplate Client requests. So I implemented ClientHttpRequestInterceptor. And I add the interceptor in my RestTemplateBuilder config like shown below. The problem is that when the RestTemplate makes the HTTP call it throws following exception:

java.lang.ClassCastException: org.springframework.http.client.InterceptingClientHttpRequestFactory cannot be cast to org.springframework.http.client.HttpComponentsClientHttpRequestFactory
Run Code Online (Sandbox Code Playgroud)

RestTemplate Bean Creation :

@Bean
  public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
    poolingConnectionManager.setMaxTotal(restTemplateProps.getMaxConnectionsPerPool());
    poolingConnectionManager.setDefaultMaxPerRoute(restTemplateProps.getMaxDefaultConnectionPerRoute());
    CloseableHttpClient client = HttpClientBuilder.create().setConnectionManager(poolingConnectionManager).build();
    ClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(client);
    restTemplateBuilder = …
Run Code Online (Sandbox Code Playgroud)

java spring-boot spring-rest

3
推荐指数
1
解决办法
4586
查看次数

如何在 PHP 中的 href 链接中发送多个值?

我想使用链接将多个值发送到不同的页面href。但我检索到的只是前两个值,其余的显示未定义索引的错误。

我的代码是:

<?php 

echo "<a href='index.php?choice=search&cat=".$cat."&subcat=".$subcat."&srch=".$srch."&page=".$next."'> Next </a>";

?>
Run Code Online (Sandbox Code Playgroud)

我只得到“选择”和“猫”的值。请告诉我上面的代码有什么问题。

php

1
推荐指数
1
解决办法
4万
查看次数