【问题标题】:How to receive propertyPath in Hibernate custom message interpolation?如何在 Hibernate 自定义消息插值中接收 propertyPath?
【发布时间】:2013-08-20 08:28:03
【问题描述】:

当我实现 MessageInterpolator 时,我没有找到接收正在发生验证的 propertyPath/propertyName 的方法。在某些情况下,我想将 propertyName 添加到错误消息中。

但是,我可以在 ConstraintViolation 的 bean 验证失败后检索它。

propertyName = constraintViolation.getPropertyPath().toString();

如何在消息插值中检索此日期之前

附:我在 Hibernate 的 JIRA https://hibernate.atlassian.net/browse/BVAL-233 中看到了未解决的问题,所以,我猜没有 clean/standard 方法可以做到这一点......

【问题讨论】:

    标签: hibernate validation jpa bean-validation hibernate-validator


    【解决方案1】:

    我不知道有什么方法可以做到这一点,既不能移植也不能通过 Hibernate Validator 中的特定 API。在 Hibernate Validator 5.1 中有 an API 用于使其他对象可用于消息插值。以这种方式公开属性路径可能是一个想法。你能在我们的 JIRA 实例中为此打开一个feature request 吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多