Java 不推荐使用休眠@NotEmpty

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48986091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:56:11  来源:igfitidea点击:

Hibernate @NotEmpty is deprecated

javahibernatespring-mvc

提问by Brijesh Soni

I am using 5.2.13.Finalversion of hibernate-coreand 5.2.13.Final version of hibernate-validator.

我正在使用5.2.13.Final版本的hibernate-core和 5.2.13.Final 版本的hibernate-validator

@NotEmpty
@Column(name = "SSO_ID", unique = true, nullable = false)
private String ssoId;

@NotEmptycomes in picture when I need the following validation message from themessage.propertiesfile when ssoIdis empty:

@NotEmpty当我需要message.properties文件中的以下验证消息时,该文件ssoId为空时出现:

NotEmpty.user.ssoId=SSO ID can not be blank.

NotEmpty.user.ssoId=SSO ID can not be blank.

But @NotEmptyis deprecated in the latest version. What is its equivalent?

@NotEmpty在最新版本中已弃用。它的等价物是什么?

采纳答案by davidxxx

Generally, as something is marked as deprecated in a javadoc, the javadoc explains also what is the alternative to.

通常,由于某些内容在 javadoc 中被标记为已弃用,因此 javadoc 还解释了替代方法。

The org.hibernate.validator.constraints.NotEmpty annotation javadocstates (emphasis is mine) :

org.hibernate.validator.constraints.NotEmpty注释的javadoc国家(重点是我的):

Deprecated. use the standard javax.validation.constraints.NotEmptyconstraint instead

已弃用。改用标准 javax.validation.constraints.NotEmpty约束

Note that since Hibernate 5, Hibernate deprecated several of its specific validation constraint classes in favor to standard JSR 380-bean validationclasses.
Note also that the Hibernate Validator 6library is actually the reference implementation of this JSR.

请注意,从 Hibernate 5 开始,Hibernate 弃用了几个特定的​​验证约束类,转而使用标准的JSR 380-bean 验证类。
另请注意,Hibernate Validator 6库实际上是此 JSR 的参考实现

Hereis an updated list of deprecated API for Hibernate validator.

是 Hibernate 验证器的已弃用 API 的更新列表。

回答by user3129211

Use import javax.validation.constraints.NotBlank;instead of import org.hibernate.validator.constraints.NotBlank;

使用 import javax.validation.constraints.NotBlank; 而不是导入 org.hibernate.validator.constraints.NotBlank;