Hibernate groupproperty method — sets the property column participating in the grouping
•
Java
groupProperty(String propertyName)
Example
Criteria criteria = session.createCriteria(UserForm.class); //获取Criteria对象
criteria.setProjection(Projections.projectionList() //设置投影查询列
.add(Projections.groupProperty("username"))
.add(Projections.rowCount(),"count")); //设置添加分组的属性列
list = criteria.list(); //执行查询语句,获取查询结果集
Iterator it = list.iterator(); //获取查询迭代器
while(it.hasNext()){ //循环遍历迭代器
Object[] o = (Object[])it.next();
System.out.println("用户名:"+o[0]+"人数:"+o[1]);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
