![](/img/trans.png)
[英]How to cast from a list<Objects> when using Hibernate query language?
[英]How to filterd mail domain from the list of emails using hibernate query
我有一个像emais数据列表abc@gmail.com
, abc@yahoo.com
, asd@gmail.com
, asd@yahoo.com
, sdf@gmail.com
。
现在,我想将电子邮件域列表过滤为“ gmail”,所有数据都应过滤并仅显示gmail ID列表,而不显示其他电子邮件ID。
我的代码是:
List<String> EmaiList = (List<String>) session.createQuery("select email from UserDto where email like :lk and type" +
(isMailStuff ? " in (:mailTypes)" : " not in (:mailTypes)"))
.setString("lk", partEmail + "%")
.setParameterList("mailTypes", UserType.mailTypes)
.list();
在此代码中,我将isMailStuff设置为'true'。 现在,我可以过滤gmail列表,但在某些地方我也可以看到其他邮件ID,例如yahoo邮件ID。
您能否让我知道此查询中是否需要任何变更。
问候,拉维
http://dev.mysql.com/doc/refman/5.1/zh-CN/string-functions.html#function_substring-index
加
where substring_index(email_column, '@', -1)='gmail.com'
如果将setString
更改为此
.setString("lk", "%" + partEmail + "%")
其中partEmail
值为@gmail
,它将返回包含模式@gmail
的电子邮件列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.