使用预测
如果我们只想检索几列,我们可以使用 Projections 类来执行此操作。例如,以下代码检索标题列
// Selecting all title columns
List review = session.createCriteria(TravelReview.class)
.setProjection(Projections.property("title"))
.list();
// Getting row count
review = session.createCriteria(TravelReview.class)
.setProjection(Projections.rowCount())
.list();
// Fetching number of titles
review = session.createCriteria(TravelReview.class)
.setProjection(Projections.count("title"))
.list();