使用休眠标准很容易获得一些字段:
SELECT user.id, user.name FROM user
Criteria cr = session.createCriteria(User.class)
.setProjection(Projections.projectionList()
.add(Projections.property("id"), "id")
.add(Projections.property("Name"), "Name"))
.setResultTransformer(Transformers.aliasToBean(User.class));
List<User> list = cr.list();
是否可以获取除“id”和“Name”字段之外的所有字段(类User有20多个字段,我不想将它们全部添加到projectionList中)?
答案 0 :(得分:0)
简单地致电:
Criteria cr = session.createCriteria(User.class).setResultTransformer(Transformers.aliasToBean(User.class));
List<User> list = cr.list();