• Hibernate property方法:指明投影对象的某个属性

    property 方法用于指明投影对象的某个属性。

    语法:

    property(String propertyName)

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

    示例

    查询数据表中的全部用户名,关键代码如下:

    Criteria criteria = session.createCriteria(UserForm.class);  //获取Criteria对象
    criteria.setProjection(Projections.property("username"));  //设置查询投影列
    list = criteria.list();  //执行查询语句获取查询结果集
    Iterator it = list.iterator();  //创建查询结果迭代器
    while(it.hasNext()){  //循环遍历迭代器
      System.out.println("用户ID:"+it.next());
    }

更多...

加载中...