首页>代码>ssm开发学校教务查询系统(高端毕业设计)>/Examination_System/src/main/java/com/system/controller/StudentController.java
package com.system.controller;
import com.system.exception.CustomException;
import com.system.po.*;
import com.system.service.CourseService;
import com.system.service.SelectedCourseService;
import com.system.service.StudentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by Jacey on 2017/7/5.
*/
@Controller
@RequestMapping(value = "/student")
public class StudentController {
@Resource(name = "courseServiceImpl")
private CourseService courseService;
@Resource(name = "studentServiceImpl")
private StudentService studentService;
@Resource(name = "selectedCourseServiceImpl")
private SelectedCourseService selectedCourseService;
@RequestMapping(value = "/showCourse")
public String stuCourseShow(Model model, Integer page) throws Exception {
List<CourseCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(courseService.getCountCouse());
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
list = courseService.findByPaging(1);
} else {
pagingVO.setToPageNo(page);
list = courseService.findByPaging(page);
}
model.addAttribute("courseList", list);
model.addAttribute("pagingVO", pagingVO);
return "student/showCourse";
}
// 选课操作
@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";
}
// 退课操作
@RequestMapping(value = "/outCourse")
public String outCourse(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));
selectedCourseService.remove(selectedCourseCustom);
return "redirect:/student/selectedCourse";
}
// 已选课程
@RequestMapping(value = "/selectedCourse")
public String selectedCourse(Model model) throws Exception {
//获取当前用户名
Subject subject = SecurityUtils.getSubject();
StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal());
List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList();
model.addAttribute("selectedCourseList", list);
return "student/selectCourse";
}
// 已修课程
@RequestMapping(value = "/overCourse")
public String overCourse(Model model) throws Exception {
//获取当前用户名
Subject subject = SecurityUtils.getSubject();
StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal());
List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList();
model.addAttribute("selectedCourseList", list);
return "student/overCourse";
}
//修改密码
@RequestMapping(value = "/passwordRest")
public String passwordRest() throws Exception {
return "student/passwordRest";
}
}
最近下载更多
奋斗的小蚂蚁 LV16
10月26日
huangzy LV12
2024年10月23日
森sdfgf LV8
2024年2月4日
t_suerinfo LV1
2023年8月28日
hedyyy LV3
2023年6月19日
qiangmin1223 LV12
2023年4月24日
ed8vid LV4
2023年3月21日
zdhsqnm LV1
2023年2月10日
LITIANYU084414 LV11
2023年1月4日
微信网友_6248713511227392 LV11
2022年12月5日
最近浏览更多
奋斗的小蚂蚁 LV16
10月26日
guwen3421
8月10日
暂无贡献等级
999772
5月7日
暂无贡献等级
2096317164
2024年11月4日
暂无贡献等级
微信网友_7104891377078272
2024年11月2日
暂无贡献等级
huangzy LV12
2024年10月23日
微信网友_7051335135711232
2024年6月24日
暂无贡献等级
matingcai
2024年5月26日
暂无贡献等级
微信网友_7006168050651136
2024年5月23日
暂无贡献等级
yangyuer LV1
2024年4月28日

