学生模块-查看个人课表
效果图:
数据库表设计(前期的表设计,实际稍微有改动):
实际的排课表实体类:
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 findByStuNo(String stuNo) {
List 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 params = new ArrayList<>();
if(stuNo != null){
//条件查询
params.add(stuNo);
}
list = (List) 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 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 toMap() {
Map 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 toMap() {
Map 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]
pageEncoding="UTF-8"%>
学生课表td {
text-align: center;
width: 10%;
}
$(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 );//设置位置
});
})
节次 | ${d.value } | ||||||
${t.value } |
*注:数据库中存的CourseTimetable的time和day都是对应两个枚举的key。