我正在尝试创建一个标准,从列中选择不同的值。如何将此值作为String返回;
我有这个:
Criteria criteria =
session.createCriteria(Students.class)
.add(Restrictions.eq("studentYear","2"))
.add(Restrictions.eq("studentSemester","1"))
.setProjection(Projections.distinct(Projections.property("studentHostel")));
任何想法将不胜感激。我可以将其转换为String值吗?
答案 0 :(得分:1)
我认为你必须像下面那样手动完成。
Criteria criteria =
session.createCriteria(Students.class)
.add(Restrictions.eq("studentYear","2"))
.add(Restrictions.eq("studentSemester","1"))
.setProjection(Projections.distinct(Projections.property("studentHostel")));
List<String> listObj = criteria.list();
StringBuffer sb = new StringBuffer();
for(String str: listObj){
sb.append(str+',');
}