• Hibernate max方法:计算某一列的最大值

    max 方法用于计算某一列的最大值。

    语法:

    max(String propertyName)

    参数说明:

    • propertyName:用于指定计算最大值的属性列的列名。

    返回值:AggregateProjection 类的对象。AggregateProjection 类为 Projection 类的子类。

    示例

    获取成绩信息表中的最高成绩,关键代码如下:

    Criteria criteria = session.createCriteria(ResultForm.class);  //获取Criteria对象
    criteria.setProjection(Projections.max("achievement"));  //获取achievement列的最大值
    double max = (Double)criteria.uniqueResult();  //获取查询结果
    System.out.println("最高成绩:"+max);

更多...

加载中...