gpt4 book ai didi

java - @ElementCollection 计数频率

转载 作者:行者123 更新时间:2023-11-30 09:36:16 26 4
gpt4 key购买 nike

我有一个这样声明的“标签”属性:

@Entity
public class BlogArticle
{
[...]
@ElementCollection(fetch = FetchType.EAGER)
Set<String> tags =new HashSet<String>();
[...]
}

此属性表示与文章关联的标签。现在我想生成一个标签云。所以我想统计每个标 checkout 现的频率。

有没有简单的方法来做到这一点? (不创建 Tag 对象?)

最佳答案

String hql = "select t, count(1) from BlogArticle a inner join a.tags t group by t";
List tagCounts = createQuery( hql ).list();

Iterator itr = tagCounts.iterator();
while ( itr.hasNext() ) {
Object[] tagCount = (Object[]) itr.next();
String tag = (String) tagCount[0];
Long count = (Long) tagCount[1];
}

关于java - @ElementCollection 计数频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10826156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com