关闭

教务管理系统-学生查询个人课表

标签: jquerysubstringsplit
3171人阅读 评论(0) 收藏 举报
分类:

学生模块-查看个人课表

效果图:


数据库表设计(前期的表设计,实际稍微有改动):

实际的排课表实体类:
package com.edu.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * 课程时间表
 *
 * xukai 2016年5月26日下午2:07:44
 */
@Entity
@Table(name = "tms_course_timetable")
public class CourseTimetable implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4427937078756586298L;

	@Id
	@SequenceGenerator(name = "seq_gener_timetable", allocationSize = 1, sequenceName = "seq_course_timetable",initialValue=1)
	@GeneratedValue(generator = "seq_gener_timetable", strategy = GenerationType.SEQUENCE)
	private Integer id;

	@ManyToOne(targetEntity = Course.class, cascade = { CascadeType.REFRESH, CascadeType.PERSIST })
	@JoinColumn(name = "course_no")
	private Course course;

	private String time;//节次

	/**
	 * 上课地点: 教学楼-教室地点 C2001
	 */
	private String location;

	private String remarks;

	private String status;

	private String day;//星期


}
Dao层的数据查询方法:
	@Override
	public List<CourseTimetable> findByStuNo(String stuNo) {
		List<CourseTimetable> list = null;
		StringBuilder hql = new StringBuilder("From CourseTimetable as t,StuCourse as s Where s.course.courseNo ="
				+ "t.course.courseNo and s.student.stuNo = ? ");
		List<Object> params = new ArrayList<>();
		if(stuNo != null){
			//条件查询
			params.add(stuNo);
		}
		list = (List<CourseTimetable>) super.getHibernateTemplate().find(hql.toString(), params.toArray());
		return list;
	}
Action的数据传输:
	@Action(value = "/view_mine_course",results={
			@Result(name = "course_timetable",location = "/student/course_timetable.jsp")
	})
	public String viewCourse(){
		List<CourseTimetable> timetables = timetableService.queryByStuNo((String)this.session.get("id"));
		this.request.put("day", EnumTimetableDay.toMap());
		this.request.put("time", EnumTimetableTime.toMap());
		this.request.put("list", timetables);
		return "course_timetable";
	}
这里还添加了两个枚举:
星期枚举
package com.edu.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 时间表星期几
 *
 * xukai 2016年5月26日下午3:22:15
 */
public enum EnumTimetableDay {

	Monday("1","星期一"),
	
	Tuesday("2","星期二"),
	
	Wednesday("3","星期三"),
	
	Thursday("4","星期四"),
	
	Friday("5","星期五"),
	
	Saturday("6","星期六"),
	
	Sunday("7","星期日");

	private String code;

	private String value;

	private EnumTimetableDay(String code, String value) {
		this.code = code;
		this.value = value;
	}
	
	public static Map<String, String> toMap() {
		Map<String, String> map = new HashMap<>();
		for (EnumTimetableDay type : values()) {
			map.put(type.getCode(), type.getValue());
		}
		return map;
	}
}
节次枚举:
package com.edu.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 课程时间表 节次
 *
 * xukai 2016年5月26日下午3:27:08
 */
public enum EnumTimetableTime {

	ONE("1","第一~二节"),
	
	TWO("2","第三~四节"),
	
	THREE("3","第五~六节"),
	
	FOUR("4","第七~八节"),
	
	FIVES("5","第九~十节"),
	
	SIX("6","第十一~十二节");

	private String code;

	private String value;

	private EnumTimetableTime(String code, String value) {
		this.code = code;
		this.value = value;
	}
	
	public static Map<String, String> toMap() {
		Map<String, String> map = new HashMap<>();
		for (EnumTimetableTime type : values()) {
			map.put(type.getCode(), type.getValue());
		}
		return map;
	}
}
最后就是页面显示了,思路:先创建一个table,然后对每个tr和td进行编号,然后根据后台传输数据,重新再td中填入数据。
传输list的样例:
CourseTimetable [id=1, course=Course [courseNo=10001, courseName=计算机网络, status=1, type=2, credit=3, times=50, teacher=Teacher [teacherNo=20120101, teacherName=张老师, password=000, political=团员, idCard=null, sex=1, nation=汉族, degree=研究生, headUrl=null, email=null, telephone=null, status=1, startDate=2012-01-01, remarks=胡编的], remarks=网络原理], time=1, location=C-1001, remarks=大班, status=1, day=4]


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生课表</title>
<style type="text/css">
td {
	text-align: center;
	width: 10%;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$('#first input').each(function () {
			var time = $(this).val().split("time=")[1].split(",")[0];//根据星期和节次,定位修改td的位置
			var day = $(this).val().split("day=")[1].substr(0,1);
			var id = '#tr_'+time+' #td_' +day;
			
			var courseName = $(this).val().split("courseName=")[1].split(",")[0];//获取课程名
			var teacherName = $(this).val().split("teacherName=")[1].split(",")[0];
			var location = $(this).val().split("location=")[1].split(",")[0];
			console.log(time+"-"+day+"-"+id);
			 $(id).text(courseName + "-" + teacherName + "-" + location );//设置位置
        });
	})
</script>
</head>
<body>
	<table border="1" align="center">
		<tr>
			<td id="first">节次
				<c:forEach items="${list }" var="l" varStatus="status">
					<input type="hidden" id="id_${status.index }" value="${l[0] }">
				</c:forEach>
			</td>
			<c:forEach items="${day }" var="d">
				<td>${d.value }</td>
			</c:forEach>
		</tr>
		<c:forEach items="${time }" var ="t" varStatus="status">
			<tr id="tr_${status.index+1 }">
				<td id="td_${status.index }">${t.value }</td>
				<td id="td_${status.index+1 }"></td>
				<td id="td_${status.index+2 }"></td>
				<td id="td_${status.index+3 }"></td>
				<td id="td_${status.index+4 }"></td>
				<td id="td_${status.index+5 }"></td>
				<td id="td_${status.index+6 }"></td>
				<td id="td_${status.index+7 }"></td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>
*注:数据库中存的CourseTimetable的time和day都是对应两个枚举的key。



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:84404次
    • 积分:1629
    • 等级:
    • 排名:千里之外
    • 原创:92篇
    • 转载:1篇
    • 译文:0篇
    • 评论:27条
    最新评论
    博客专栏
    文章分类