atitit. 统计功能框架的最佳实践(1)---- on hibernate criteria

本文介绍了一种基于Hibernate Criteria API实现统计功能的方法。该方法涵盖了如何设置聚合字段、分组字段、日期分组字段及子对象关联等功能,并通过示例展示了具体的实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

atitit. 统计功能框架的最佳实践(1)---- on hibernate criteria 

 

1. 关键字 1

2. 统计功能框架普通有有些条件选项...一个日期选项..一个日期类型(,,月份,年等) 1

3. 元数据的位置,不需要绑定class 1

4. 设置聚合字段... @reduce(" sum(timLen) "),@reduce(" Avg(timLen) ") 2

5. 设置groupby  字段  @GroupBy 2

6. 设置groupbydate  字段  @GroupBydate 3

7. Where设置@condition 3

8. 实现查询 ,,不能返回class,子能list<map> 3

9. 子对象关联 @CountRelt(uiFld="groupid",fld="departId") 3

 

1. 关键字

Hibernate criteria 日期groupby  子对象属性groupby

 

 

2. 统计功能框架普通有有些条件选项...一个日期选项..一个日期类型(,,月份,年等)

作者:: 老哇的爪子 Attilax 艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://blog.youkuaiyun.com/attilax

 

3. 元数据的位置,不需要绑定class

统计的list结果是不绑定class,,走十一个List(map>

中间,元数据放的个拉李都行了...

不过,放得个html黑头还要解释器了....使用注解实现走马中个麻烦的...林吧,还是使用注解实现兰...

 

 

4. 设置聚合字段... @reduce(" sum(timLen) "),@reduce(Avg(timLen) ")

private Integer timLen;

 

5. 设置groupby  字段 @GroupBy

 

@GroupBy

@CountRelt(uiFld="groupid",fld="departId")

Equipment eq;

 

解释器实现

Criteria c = new BaseSvs().getSession().createCriteria(this.saveObjClass);

Criteria eqCri = c.createAlias("eq", "equ", JoinType.LEFT_OUTER_JOIN);

if(this.reqMap.get("groupid")!=null && this.reqMap.get("groupid").toString().trim().length()>0 )

{

//Projections.groupProperty(propertyName) 

projectionList1.add(  Projections.groupProperty("equ.departId").as("departId"));

projectionList1.add(  Projections.groupProperty("equ.equipmentId").as("equipmentId"));

//projectionList1.add(  Projections.groupProperty("equ.mome").as("mome"));

int grpid = Integer.parseInt(   this.reqMap.get("groupid").toString());

eqCri.addRestrictions.eq("equ.departId", grpid));

}

 

6. 设置groupbydate  字段 @GroupBydate

 

或者不个这个弄个自定义的fmtr比较好的.....不过这个date雅十通常使用的,,spetion弄个中个注解也行了...

 

解释器实现

 

projectionList1.add(Projections.sqlGroupProjection(" count(*) as shouldDown, count(*) as actDown,  CONVERT(varchar(10), download_create_time ,23 ) as timRang ", "  CONVERT(varchar(10), download_create_time ,23 ) ", new String[] { "shouldDown", "actDown", "timRang" }, new Type[] { IntegerType.INSTANCE, IntegerType.INSTANCE, StringType.INSTANCE }));

 

7. Where设置@condition

留意子对象属性conditon 的设置...

 

8. 实现查询 ,,不能返回class,子能list<map>

 

不官十使用criteria ,还是sql ,都子能回归mapList,,...还以为criteria能回归class...

 

  Criteria cri=getCriteria();

    cri.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

List list=cri.list();

 

9. 子对象关联@CountRelt(uiFld="groupid",fld="departId")

Equipment eq;

 

解释器实现

 

 setCountRelt2(list_sub);   

 

private void setCountRelt2(List<Map> list_sub) {

// attilax 老哇的爪子  2_47_6   o9r 

//List<String> CountReltFldsList=getCountReltFldsList();

for (Map map : list_sub) {

//for (String fldName : CountReltFldsList) {

//Class rltCls = getFldClass(fldName);      equmnet :eq  

//Field idFld = null;

//try {

//idFld = refx.getIdFld_EXO9o(rltCls);

//} catch (cantFindMatchFieldException e) {

////  attilax 老哇的爪子 10_58_h   o9q   

////e.printStackTrace();

//core.warn(e);

//}

Object idVal = map.get("equipmentId");  //eqid

if(idVal!=null)

{

Object rltObj = getSession().get(Equipment.class,(IntegeridVal);

map.put("eq", rltObj );

}

//}

}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

我要啦免费统计
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值