小编Rem*_*emo的帖子

升级到gradle 7.x后生成两个war文件

从gradle 5.x升级到7.x后,生成两个war文件。

下面是2个war文件名

test-app-1.0.0.war
test-app-1.0.0-plain.war
Run Code Online (Sandbox Code Playgroud)

下面是使用的 gradle 插件和任务:

plugins {
    id 'war'
}

bootWar {
    launchScript()
    manifest {
        attributes 'Implementation-Version':  archiveVersion
    }
}

Run Code Online (Sandbox Code Playgroud)

我只想生成test-app-1.0.0.war. 如何解决这个问题?

java war gradle spring-boot

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

groupingBy 使用布尔值,但添加自定义字符串作为键

我有下面的代码并基于布尔值进行 groupingBy

Map<Boolean, List<Test>> products = testList
        .stream()
        .collect(Collectors.groupingBy(Test::isValidUser));
        
Run Code Online (Sandbox Code Playgroud)

我想把它收集起来Map<String, List<Test>

基于布尔值,想要将自定义键添加为“有效”和“无效”。

如果为isValidUsertrue,则要将密钥添加为“有效”,否则密钥应为“无效”

在 Java 11 中是否有可能做到这一点?

注意:没有在Test类中添加String变量

java collections java-8 java-stream collectors

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

How to find YearMonth is equal or after current month?

I want to find the month is equal or after the current YearMonth

final YearMonth yearMonth = YearMonth.of(2020, 8);
final boolean after = yearMonth.isAfter(YearMonth.now());

Run Code Online (Sandbox Code Playgroud)

Here current month is August(8) and I tried isAfter which returns false.

I want to return true for current month also.

Is any method is there in YearMonth itself?

java datetime date

2
推荐指数
1
解决办法
166
查看次数

将字符串转换为货币

我有以下字符串

String money = "USD0.00" 
Run Code Online (Sandbox Code Playgroud)

想把这个转换成 org.joda.money.Money

我是否需要在此处拆分货币单位和双倍值,并需要在 Money. 或者有任何库 api 可以转换它吗?

java java-8 joda-money

2
推荐指数
1
解决办法
96
查看次数

无法应用插件“no.nils.wsdl2java”。未找到名称为“compile”的配置

迁移到 gradle 7.x 时出现以下错误


* What went wrong:
An exception occurred applying plugin request [id: 'no.nils.wsdl2java', version: '0.12']
> Failed to apply plugin 'no.nils.wsdl2java'.
   > Configuration with name 'compile' not found.

Run Code Online (Sandbox Code Playgroud)

下面是在build.gradle中添加的wsdl2java


plugins {
    id("no.nils.wsdl2java") version "0.12"
    `java-library`
}

buildscript {
    dependencies {
        classpath("no.nils:wsdl2java:0.12")
    }
}

Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

gradle build.gradle gradle-kotlin-dsl

2
推荐指数
1
解决办法
5984
查看次数

如何收集与 Java 8 中的 List 相同的最大数字键

我想从 Java 8+ 中的 Map<String,Integer> 收集最大数字列表的关联键

例如:

final Map<String, Integer> map = new HashMap<>();
map.put("first", 50);
map.put("second", 10);
map.put("third", 50);
Run Code Online (Sandbox Code Playgroud)

在这里我想返回与最大值关联的键列表。

对于上面的例子,预期输出是[first,third]。因为这两个键具有相同的最大值。

我尝试使用以下方法,但只能获得单个最大密钥。

final String maxKey = map.entrySet()
    .stream()
    .max(Map.Entry.comparingByValue())
    .map(Map.Entry::getKey)
    .orElse(null);

final List<String> keysInDescending = map.entrySet()
    .stream()
    .sorted(Map.Entry.<String,Integer>comparingByValue().reversed())
    .map(Map.Entry::getKey)
    .collect(Collectors.toList());

System.out.println(maxKey); // third
System.out.println(keysInDescending); //[third, first, second]
Run Code Online (Sandbox Code Playgroud)

但我的预期输出是[第一,第三]。在Java 8+版本中如何实现呢?

java collections java-stream

0
推荐指数
1
解决办法
300
查看次数

使用 Jackson 在 Spring Boot 中反序列化 requestParam 枚举不区分大小写

我有以下 api

  @GetMapping(value = "/employees")
    public List<Employee> getEmployees(
        @RequestParam(value = "mode", required = false) final EmployeeMode mode) {
        //calling service from here
    }
Run Code Online (Sandbox Code Playgroud)

我将 EmployeeMode 枚举作为 requestParam。

public enum EmployeeMode {

    REGULAR,
    ALL,
    TEMPROARY
}
Run Code Online (Sandbox Code Playgroud)

我想接受不区分大小写的请求。尝试使用@JsonAlias@JsonCreatorobjectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);spring.jackson.mapper.accept-case-insensitive-enums: true对我来说没有任何作用。

我正在使用 Spring Boot 2.5.5。

如何使用 requestParam 接受不区分大小写的请求?如果 requestParam 为空/null,则需要将默认枚举设置为 ALL。

java enums spring jackson spring-boot

0
推荐指数
1
解决办法
969
查看次数

如何从当前日期(java.util.Date)获取该月的第一天?

想要从当前日期获取该月的第一天。

为了得到我正在做的 org.apache.commons.lang3.time.DateUtils 以以下格式返回

DateUtils.truncate(new Date(), 2);
Run Code Online (Sandbox Code Playgroud)

这将返回预期输出,如下所示:

Fri Jul 01 00:00:00 IST 2022
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以使用与上述相同的日期时间格式获取当月的第一天吗?

java datetime date

-2
推荐指数
1
解决办法
2558
查看次数