为电子邮件存在制定自定义的hibernate验证注释 [英] Make custom hibernate validation annotation for email existence
问题描述
我想知道是否可以创建自定义hibernate验证注释
来检查数据库中的电子邮件是否存在(调用dao方法,如果电子邮件存在,则返回true)
所以我可以这样做:
@NotBlank(message =email is required)
@Email(message ={invalid.email})
@EmailExist(message ={email.exist})
@Column(name =email,length = 155 ,nullable = false)
private String email;
如果可能,请提前告知样本,谢谢。
是的,它应该是可能的,你只需要实现你的自定义注释验证器实现。
使用真正的AspectJ并使用 @Configurable
注释该类,然后在每个其他spring bean中使用 @Inject
。 / b>
@See:
i was wondering if it's possible to make custom hibernate validation annotation that will check in the database if the email exist or not (call dao method and return true if the email exist)
so i can do something like:
@NotBlank(message = "email is required")
@Email(message = "{invalid.email}")
@EmailExist(message = "{email.exist}")
@Column(name = "email", length = 155, nullable = false)
private String email;
please advise with a sample if possible, thanks in advance.
Yes it should be possible, you just need to implement your custom annotation validator implementation.
If you use real AspectJ and annotate the class with @Configurable
then you an use @Inject
like in every other spring bean.
@See:
- Spring Configurable: Spring Reference Chapter 7.8.1 Using AspectJ to dependency inject domain objects with Spring
- JSR-000303 Bean Validation 1.0 Final Release Specification Chapter 2 Constraint Definition
- Example of an custom Validation
这篇关于为电子邮件存在制定自定义的hibernate验证注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!