使用預測
如果我們只想檢索幾列,我們可以使用 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();