gpt4 book ai didi

java - Bean 验证字符串的集合不为空

转载 作者:行者123 更新时间:2023-12-02 07:41:59 25 4
gpt4 key购买 nike

我有一个字符串集合,现在我想确保该集合不仅不为空,而且该集合中的每个字符串都不包含空白输入。

 @NotEmpty
public List<String> getDescriptions() // not empty collection


@NotEmpty @NotBlank
public List<String> getDescriptions() // NotBlank isn't applicable on collections

除了将字符串包装到类中或创建自定义 @NotBlankCollectionEntries 之外,还有其他方法吗?

最佳答案

你可以使用这样的东西:

@NotNull
@Size(min = 1)
public List<@NotBlank @Size(max = 123) String> getDescriptions() // not empty collection


@NotNull
@Size(min = 1)
public List<@NotBlank @Size(max = 123)> getDescriptions()```

关于java - Bean 验证字符串的集合不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26860418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com