Constraint中清空validatedBy

Constraint中清空validatedBy

本文介绍了在@Constraint中清空validatedBy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到所有内置约束在 @Constraint 中的 validatedBy 参数都有一个空值。即 @Constraint(validatedBy = {})

I noticed that all built-in constraints have an empty value for the validatedBy parameter in @Constraint. i.e. @Constraint(validatedBy = {})

首先,为什么允许它们为 validatedBy ?我认为你可以只为不需要附加验证的约束组合留空吗?

First, why are they allowed to have an empty value for validatedBy? I thought you can leave it blank only for constraint composition that does not need addtional validation?

另外,请注意Hibernate Validator仍然可以为每个构建的查找验证器实现类-in约束,尽管 validatedBy 是空的,但如果我将validatedBy留给我的约束,我的自定义验证器永远不会被拾取。为什么?

Also, note that the Hibernate Validator can still find a validator implementation class for each built-in constraint, despite the validatedBy is empty, but if I leave the validatedBy blank for my constraint, my custom validator never gets picked up. Why is that?

谢谢。

推荐答案

内置以特定于实现的方式处理,并以编程方式配置它们的验证器。

Those built-in are treated in special implementation-specific way and their validators are configured programmatically.

对于Hibernate Validator,它是在。我认为你的自定义约束不能达到同样的效果。

For Hibernate Validator it's done in ConstraintHelper.java. I think you can't achieve the same for your custom constraints.

这篇关于在@Constraint中清空validatedBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:07