简体   繁体   中英

JSR 303 - Name of the annotated field in the custom validator

I have a question about custom annotations. More precisely, do I have access to the name of the annotated field inside the custom validator ? If yes, how do I access this?

Thanks

No, you can't access the name of the validated element from within a constraint validator. It is exposed by the resulting constraint violation, though (via getPropertyPath() ).

在休眠实现中,可以使用反射ConstraintValidatorContext.basePath.currentLeafNode.name来获取它。

您可以通过以下exp访问路径

((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM