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());
}

本文标题:Hibernate property方法:指明投影对象的某个属性

本文地址:http://www.hosteonscn.com/6455.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注