欢迎光临
我们一直在努力

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());
}
赞(0) 打赏
未经允许不得转载:hosteons中文网 » Hibernate property方法:指明投影对象的某个属性

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册