[英]JSR 303 - Name of the annotated field in the custom validator
我对自定义注释有疑问。 更准确地说,我可以访问自定义验证器中带注释的字段的名称吗? 如果是,我该如何访问?
谢谢
不可以,您不能从约束验证器中访问已验证元素的名称。 但是,它会由于违反约束而暴露出来(通过getPropertyPath()
)。
在休眠实现中,可以使用反射ConstraintValidatorContext.basePath.currentLeafNode.name来获取它。
您可以通过以下exp访问路径
((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.