@Constraint(validated by = {}) validated by 为空

The javax.validation.constraints leaves the validators to the implementation. Hibernate provides validators to these constraints, and registers them when bootstrapping.

You can set the validators via XML without using @Constraint(validatedBy = { }). However, this is usually used to add to/replace the provided validators with your own. I'm not sure how it will help you since you still need to reference the constraint validator.

Example of using XML constraint definition:

<constraint-definition annotation="org.mycompany.CheckCase">
    <validated-by include-existing-validators="false">
        <value>org.mycompany.CheckCaseValidator</value>
    </validated-by>
</constraint-definition>

See: Configuring via XML

The upcoming 5.2 release provides more ways such as using a service loader or implementing ConstraintDefinitionContributor. See: Providing constraint definitions

转载:https://stackoverflow.com/questions/26544588/hibernate-validator-to-validate-constraints-if-constraintvalidated-by

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容