首页>代码>ssm开发学校教务查询系统(高端毕业设计)>/Examination_System/src/main/java/com/system/controller/StudentController.java
001 | package com.system.controller; |
002 |
003 | import com.system.exception.CustomException; |
004 | import com.system.po.*; |
005 | import com.system.service.CourseService; |
006 | import com.system.service.SelectedCourseService; |
007 | import com.system.service.StudentService; |
008 | import org.apache.shiro.SecurityUtils; |
009 | import org.apache.shiro.subject.Subject; |
010 | import org.springframework.stereotype.Controller; |
011 | import org.springframework.ui.Model; |
012 | import org.springframework.web.bind.annotation.RequestMapping; |
013 |
014 | import javax.annotation.Resource; |
015 | import java.util.List; |
016 |
017 | /** |
018 | * Created by Jacey on 2017/7/5. |
019 | */ |
020 | @Controller |
021 | @RequestMapping (value = "/student" ) |
022 | public class StudentController { |
023 |
024 | @Resource (name = "courseServiceImpl" ) |
025 | private CourseService courseService; |
026 |
027 | @Resource (name = "studentServiceImpl" ) |
028 | private StudentService studentService; |
029 |
030 | @Resource (name = "selectedCourseServiceImpl" ) |
031 | private SelectedCourseService selectedCourseService; |
032 |
033 | @RequestMapping (value = "/showCourse" ) |
034 | public String stuCourseShow(Model model, Integer page) throws Exception { |
035 |
036 | List<CourseCustom> list = null ; |
037 | //页码对象 |
038 | PagingVO pagingVO = new PagingVO(); |
039 | //设置总页数 |
040 | pagingVO.setTotalCount(courseService.getCountCouse()); |
041 | if (page == null || page == 0 ) { |
042 | pagingVO.setToPageNo( 1 ); |
043 | list = courseService.findByPaging( 1 ); |
044 | } else { |
045 | pagingVO.setToPageNo(page); |
046 | list = courseService.findByPaging(page); |
047 | } |
048 |
049 | model.addAttribute( "courseList" , list); |
050 | model.addAttribute( "pagingVO" , pagingVO); |
051 |
052 | return "student/showCourse" ; |
053 | } |
054 |
055 | // 选课操作 |
056 | @RequestMapping (value = "/stuSelectedCourse" ) |
057 | public String stuSelectedCourse( int id) throws Exception { |
058 | //获取当前用户名 |
059 | Subject subject = SecurityUtils.getSubject(); |
060 | String username = (String) subject.getPrincipal(); |
061 |
062 | SelectedCourseCustom selectedCourseCustom = new SelectedCourseCustom(); |
063 | selectedCourseCustom.setCourseid(id); |
064 | selectedCourseCustom.setStudentid(Integer.parseInt(username)); |
065 |
066 | SelectedCourseCustom s = selectedCourseService.findOne(selectedCourseCustom); |
067 |
068 | if (s == null ) { |
069 | selectedCourseService.save(selectedCourseCustom); |
070 | } else { |
071 | throw new CustomException( "该门课程你已经选了,不能再选" ); |
072 | } |
073 |
074 | return "redirect:/student/selectedCourse" ; |
075 | } |
076 |
077 | // 退课操作 |
078 | @RequestMapping (value = "/outCourse" ) |
079 | public String outCourse( int id) throws Exception { |
080 | Subject subject = SecurityUtils.getSubject(); |
081 | String username = (String) subject.getPrincipal(); |
082 |
083 | SelectedCourseCustom selectedCourseCustom = new SelectedCourseCustom(); |
084 | selectedCourseCustom.setCourseid(id); |
085 | selectedCourseCustom.setStudentid(Integer.parseInt(username)); |
086 |
087 | selectedCourseService.remove(selectedCourseCustom); |
088 |
089 | return "redirect:/student/selectedCourse" ; |
090 | } |
091 |
092 | // 已选课程 |
093 | @RequestMapping (value = "/selectedCourse" ) |
094 | public String selectedCourse(Model model) throws Exception { |
095 | //获取当前用户名 |
096 | Subject subject = SecurityUtils.getSubject(); |
097 | StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal()); |
098 |
099 | List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList(); |
100 |
101 | model.addAttribute( "selectedCourseList" , list); |
102 |
103 | return "student/selectCourse" ; |
104 | } |
105 |
106 | // 已修课程 |
107 | @RequestMapping (value = "/overCourse" ) |
108 | public String overCourse(Model model) throws Exception { |
109 |
110 | //获取当前用户名 |
111 | Subject subject = SecurityUtils.getSubject(); |
112 | StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal()); |
113 |
114 | List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList(); |
115 |
116 | model.addAttribute( "selectedCourseList" , list); |
117 |
118 | return "student/overCourse" ; |
119 | } |
120 |
121 | //修改密码 |
122 | @RequestMapping (value = "/passwordRest" ) |
123 | public String passwordRest() throws Exception { |
124 | return "student/passwordRest" ; |
125 | } |
126 |
127 |
128 |
129 | } |

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日
jiangchen666888 LV1
2022年11月30日

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日
op123129
2024年4月15日
暂无贡献等级
阿昌先生 LV13
2024年3月26日