1 创建一个VO,ClassRoomCityVO
private Long locationid;
private String labName;
private String cityName;
2 DAO层
public List<ClassRoomCityVO> fetchAllClassRoomCity(String cityName){
DetachedCriteriaBuilder query=DetachedCriteriaBuilder.instance(Classroom.class, "cr");
query.innerJoin("cr.city", "ct");
query.addEq("ct.cityName", cityName);
query.addEq("cr.type", ClassroomType.Lab);
query.addEq("cr.deleted", false);
query.setProjection(Projections.projectionList()
.add(Projections.property("cr.code"), "labName")
.add(Projections.property("cr.id"), "locationid")
.add(Projections.property("ct.cityName"), "cityName")
);
query.getDetachedCriteria().setResultTransformer(new AliasToBeanResultTransformer(ClassRoomCityVO.class));
return this.selectE(query);
}
3获得有lab的所有城市
/**
* get citys which have labs
*/
@Override
@Transactional
public List<String> getCitysHavingLabs() {
List<String> retCitys = Lists.newArrayList();
List<ClassRoomCityVO> clas = clsRoom.fetchCitysHavingLabs();
if (CollectionUtils.isNotEmpty(clas)) {
for (ClassRoomCityVO vo : clas) {
retCitys.add(vo.getCityName());
}
}
return retCitys;
}