功能模块
登录界面
管理员端
教师端
学生端
部分源码
//登录表单处理
@RequestMapping(value = "/login", method = {RequestMethod.POST})
public String login(Userlogin userlogin) throws Exception {
//Shiro实现登录
UsernamePasswordToken token = new UsernamePasswordToken(userlogin.getUsername(),
userlogin.getPassword());
Subject subject = SecurityUtils.getSubject();
//如果获取不到用户名就是登录失败,但登录失败的话,会直接抛出异常
subject.login(token);
if (subject.hasRole("admin")) {
return "redirect:/admin/showStudent";
} else if (subject.hasRole("teacher")) {
return "redirect:/teacher/showCourse";
} else if (subject.hasRole("student")) {
return "redirect:/student/showCourse";
}
return "/login";
}
// 学生信息显示
@RequestMapping("/showStudent")
public String showStudent(Model model, Integer page) throws Exception {
List<StudentCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(studentService.getCountStudent());
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
list = studentService.findByPaging(1);
} else {
pagingVO.setToPageNo(page);
list = studentService.findByPaging(page);
}
model.addAttribute("studentList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showStudent";
}
<select id="findByPaging" parameterType="PagingVO" resultType="StudentCustom">
select student.*, college.collegeName
from student, college
WHERE student.collegeID = college.collegeID
limit #{toPageNo}, #{pageSize}
</select>
// 选课操作
@RequestMapping(value = "/stuSelectedCourse")
public String stuSelectedCourse(int id) throws Exception {
//获取当前用户名
Subject subject = SecurityUtils.getSubject();
String username = (String) subject.getPrincipal();
SelectedCourseCustom selectedCourseCustom = new SelectedCourseCustom();
selectedCourseCustom.setCourseid(id);
selectedCourseCustom.setStudentid(Integer.parseInt(username));
SelectedCourseCustom s = selectedCourseService.findOne(selectedCourseCustom);
if (s == null) {
selectedCourseService.save(selectedCourseCustom);
} else {
throw new CustomException("该门课程你已经选了,不能再选");
}
return "redirect:/student/selectedCourse";
}
//查询指定学生成绩
public SelectedCourseCustom findOne(SelectedCourseCustom selectedCourseCustom) throws Exception {
SelectedcourseExample example = new SelectedcourseExample();
SelectedcourseExample.Criteria criteria = example.createCriteria();
criteria.andCourseidEqualTo(selectedCourseCustom.getCourseid());
criteria.andStudentidEqualTo(selectedCourseCustom.getStudentid());
List<Selectedcourse> list = selectedcourseMapper.selectByExample(example);
if (list.size() > 0) {
SelectedCourseCustom sc = new SelectedCourseCustom();
BeanUtils.copyProperties(list.get(0), sc);
Student student = studentMapper.selectByPrimaryKey(selectedCourseCustom.getStudentid());
StudentCustom studentCustom = new StudentCustom();
BeanUtils.copyProperties(student, studentCustom);
sc.setStudentCustom(studentCustom);
return sc;
}
return null;
}