多表关联(二)-hql语句查询_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 多表关联(二)-hql语句查询

多表关联(二)-hql语句查询

 2013/11/30 15:19:01  rcm5433  程序员俱乐部  我要评论(0)
  • 摘要:Stringhql="selectnewcom.sinosoft.education.prototype.TeacherInfoBean("+"ti.teacherId,"+"ti.teacherName,"+"(selectmin(pt.teacSchoolStartTime)fromti.sysEduProjectTeachersptwherept.teacSchoolEndTime>:endtimeandpt.teacSchoolStartTime<=:endtime)
  • 标签:Hql
class="java" name="code">
String hql="select new com.sinosoft.education.prototype.TeacherInfoBean(" +
				"ti.teacherId," +
				"ti.teacherName," +
				"(select min(pt.teacSchoolStartTime) from ti.sysEduProjectTeachers pt where pt.teacSchoolEndTime >:endtime and pt.teacSchoolStartTime <=:endtime)," +
				"(select min(pt.teacSchoolEndTime) from ti.sysEduProjectTeachers pt where pt.teacSchoolEndTime >:endtime and pt.teacSchoolStartTime <=:endtime)," +
				"isnull((select avg(pl.lessonTeacherPoint) from  ti.sysEduProjectLessons pl ),0.0)" +
				") " +
				"from SysTeaTeactherInfo ti left join  ti.sysTeaProfFields pf  " +
				"where concat(',',trim(str(pf.fieldId)),',',pf.fieldFatherStr) like "+"'%,"+fieldId.toString()+",%'" ;
		List<TeacherInfoBean> teacherIds=this.findByNamedParam(hql,new String[]{"endtime"},new Object[]{DateUtil.parse("2013-11-29")});
		for(TeacherInfoBean id:teacherIds)
		{
			System.out.println(id.getTeacherName());
			System.out.println(id.getTeacherId());
			System.out.println(id.getAvg());
			System.out.println(DateUtil.toString(id.getComeTime()));
			System.out.println(DateUtil.toString(id.getEndTime()));
		}
		String countHql="select count(*)"+
		"from SysTeaTeactherInfo ti " +
		"left join  ti.sysTeaProfFields pf " +
		"left join ti.sysEduProjectTeachers pt " +
		"where concat(',',trim(str(pf.fieldId)),',',pf.fieldFatherStr) like "+"'%,"+fieldId.toString()+",%' " +
		"and (pt.teacSchoolEndTime >=:endtime)or(pt.teacSchoolEndTime <= :endtime)" ;
		System.out.println("=======================================");
		return this.findByHqlOnPage(hql, page, countPerPage, new String[]{"endtime"},new Object[]{DateUtil.parse("2013-11-29")},countHql);



同时需要自定义teacherbean 且bean中的属性必须和hql语句中的元素顺序相同,否则可能会出现传值错误
发表评论
用户名: 匿名