为电子邮件存在制定自定义的hibernate验证注释 [英] Make custom hibernate validation annotation for email existence

查看:131
本文介绍了为电子邮件存在制定自定义的hibernate验证注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以创建自定义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:

这篇关于为电子邮件存在制定自定义的hibernate验证注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆