我们可以连接Hibernate HQL查询中的两个属性吗? [英] Can we concatenate two properties in Hibernate HQL query?
本文介绍了我们可以连接Hibernate HQL查询中的两个属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比方说,我有一个带有两列的表 firstname
和 lastname
带有String数据类型。通常我写我的hql查询,如
select firstname,lastname from contact
我可以编写连接两个属性的hql查询吗?
可能类似于从联系人中选择firstname + lastname作为全名
<选择concat(c.firstname,c.lastname)作为联系人的全名c
$ c $> c>
或者,如果您想要分隔符:
从联系人中选择concat(c.firstname,'',c.lastname)作为全名c
请参阅文档。
Lets say I have one table with two columns firstname
and lastname
with String datatype. Normally I write my hql query like
"select firstname,lastname from contact"
Can I write a hql query which concatenates both property ?
Maybe something like "select firstname+lastname as fullname from Contact"
解决方案
select concat(c.firstname, c.lastname) as fullname from Contact c
or, if you want a separator:
select concat(c.firstname, ' ', c.lastname) as fullname from Contact c
See the documentation.
这篇关于我们可以连接Hibernate HQL查询中的两个属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文