本文介绍了选择标准只有几列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 从ioa_book选择aaa,bbb,ccc,ddd 

如图所示,它正在击打表ioa_book并且只选择了几列,相应的pojo名称是boop ..现在我想将它转换为休眠标准,但它加载了所有不需要的列,我仍然想使用标准并选择列本身,请告知如何实现此目的。



所以我就这样走了......

  Criteria criteria = session.createCriteria(boop。类); 
列表< boop> books = criteria.list();

请指教

解决方案
  criteria.setProjection(
Projections.projectionList()
.add(Projections.property(aaa))
.add (Projections.property(bbb))
.add(Projections.property(ccc))
);
List< Object []> result = criteria.list();

这是。


I have the database query such as ,..

select aaa, bbb, ccc, ddd from ioa_book

as shown it is hitting the table ioa_book and only selecting few columns , the corresponding pojo name is boop .. and now I want to convert it into criteria of hibernate one but it loads all the columns that i do not want , i still want to use criteria and with selected columns itself , please advise how to achieve this..

so I have gone by this way...

 Criteria criteria = session.createCriteria(boop.class);
 List<boop> books = criteria.list();

please advise

解决方案
criteria.setProjection(
    Projections.projectionList()
        .add(Projections.property("aaa"))
        .add(Projections.property("bbb"))
        .add(Projections.property("ccc")) 
    );
List<Object[]> result = criteria.list();

This is documented.

这篇关于选择标准只有几列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:26