在使用hibernate时,我们需要直接查询其中的某几个字段,除了用getSession().createSQLQuery(sql)这种方式外,还有一种方式就是使用Projection
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Cmxxxx.class,"z");
//detachedCriteria.setProjection( Property.forName("sname") ) //对于查询单个字段
ProjectionList pr = Projections.projectionList().add(Property.forName("sname") ).add(Property.forName("id"));
detachedCriteria.setProjection(pr);
detachedCriteria.add( Property.forName("linkno").eq(276208590045700L));
List res = cmxxxDao.find(detachedCriteria);
对于多个字段的查询,就需要ProjectionList,然后将需要查询的字段用Property映射
现在很多文章都没有提出这点,本人提出来了