SpringBoot + Servlet + Mybatis+ layui 学生选课管理系统
課程設計目的
本次課設做的系統為學生課程設計管理系統,鑒于學校規模的不斷擴大,而且隨著每年的擴招,人數不斷的增加,每次課程設計都采用手工操作,費時費力。為了解決這個問題,決定做一個課程設計管理系統,對每個學期選修課程設計的學生基本情況作個統計。學生可以在系統中注冊賬號,登錄后學生從該系統中選題,填寫同組學生的姓名,組長等基本情況;查詢自己的課程設計成績,課程設計的選擇情況,成績的合格情況,小組成員信息,上課程設計報告的上傳,下載,刪除,預覽等功能。老師通過該系統添加課設信息,查看學生的選題情況,給出學生的分數。這有利于老師教學,及時了解學生的情況,提高教學質量,減輕老師的工作量,改善原有的比較繁鎖的工作。
題目基本情況
本系統涉及權限管理,以老師,學生分別登錄以進行不同的操作,老師可以對查看學生信息,給出學生成績查看學生選題情況,添加課設信息。學生可以添加同組成員信息選擇課程設計,退掉課程設計,查看課程設計的成績,上傳實驗報告.為了提高信息的處理效率,設計一款小型的課程設計管理系統。將數據庫的內容通過web服務器配合前端框架在瀏覽器展現出來,達到直觀,方便的管理目的。
數據庫表設計
教師屬性:教師號,姓名,職稱,密碼。
學生屬性:學號,姓名,班級,密碼。
題目屬性:課題號,課題目名稱,題目信息,教工號。
選題屬性:學號,題號,成績,組號。
小組屬性:組號,組員,組長。
文件屬性:文件號,文件名,后綴,路徑大小,類型,下載次數,上傳時間,學號
技術棧
數據庫連接池技術 ?maven工具????servlet技術
Ajax請求 ?Spring-Boot框架 ??Mybatis框架 ???JSON數據格式 ????????????????????????????????????????????????????????
?commons-fileupload組件 ?layui框架 ?
程序流程圖
?
?
5.3.1登錄操作
本程序設計的權限管理中,不同身份可以進行的操作不一樣,因此不同的身份,決定執行什么樣的操作,如圖6-1所示為教師登錄驗證界面,前端使用leyui框架布局,
驗證碼使用BufferedImage類繪制,用戶輸入信息后進行后臺的邏輯判斷,成功則進入到后臺管理界面。若用戶名和姓名和驗證碼輸入正確,則跳轉到對應的請求映射,若勾選記住密碼,則會在信息全部正確匹配后將正確的信息存入cookie,若其中一項輸入錯誤,則會重新定向到登錄界面。
圖6-1教師登錄界面
圖6-2學生登錄界面
登錄部分代碼:
Dao層:@Select("SELECT * from student where stdname =#{stdname} and stdpassword =#{stdpassword}")public Student findstudentByNameAndPassword(Student student);//通過用戶的姓名和密碼查詢Controller層:@RequestMapping("/tologin")public String index() {return "login";}//登錄1@RequestMapping(value = "/login")public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response, Student student) throws Exception {String name = request.getParameter("stdname");String pwd = request.getParameter("stdpassword");String yzm = request.getParameter("captcha");String shenfen = request.getParameter("shenfen");HttpSession session = request.getSession();String code = (String) session.getAttribute("code");String rember = request.getParameter("rememberMe");//3.處理跳轉//創建ModelAndView對象ModelAndView mav = new ModelAndView();if (yzm.equals(code)) {Student student_find = studentService.login(student);System.out.println(student_find);if (student_find != null) {//1.辦卡String cusername = java.net.URLEncoder.encode(name, "utf-8");Cookie cookie1 = new Cookie("uname", cusername);Cookie cookie2 = new Cookie("passwd", pwd);//3.設置范圍/* cookie1.setPath("/mydemo3/");cookie2.setPath("/mydemo3/");*/if ("true".equals(rember)) {//2.設置時效(一次瀏覽器的關閉)cookie1.setMaxAge(60 * 60 * 24 * 10);cookie2.setMaxAge(60 * 60 * 24 * 10);} else {cookie1.setMaxAge(0);cookie2.setMaxAge(0);}//4.給客戶response.addCookie(cookie1);response.addCookie(cookie2);//向模型對象中添加數據mav.addObject("student", student_find);session.setAttribute("stulogin", student_find);session.setAttribute("studentname", student.getStdname());session.setAttribute("stdpwd", student.getStdpassword());//設置邏輯視圖名mav.setViewName("studentstage");//返回ModelAndView對象return mav;} else {mav.addObject("name", "請重新登錄!");//設置邏輯視圖名mav.setViewName("login");//返回ModelAndView對象return mav;}} else {mav.setViewName("login");}return mav;}驗證碼:public class CaptcahCode {public static String drawImageVerificate(HttpServletResponse response) {//定義驗證碼的寬度和高度int width = 120;int height = 25;//在內存中創建圖片BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//創建圖片上下文Graphics2D g = image.createGraphics();//產生隨機對象,此隨機對象主要用于算術表達式的數字Random random = new Random();//設置背景g.setColor(getRandomColor(240, 250));//設置字體g.setFont(new Font("微軟雅黑", Font.PLAIN, 22));//開始繪制g.fillRect(0, 0, width, height);//干擾線的繪制,繪制干擾線到圖片中g.setColor(getRandomColor(180, 230));for (int i = 0; i < 100; i++) {int x = random.nextInt(width);int y = random.nextInt(height);int x1 = random.nextInt(60);int y1 = random.nextInt(60);g.drawLine(x, y, x1, y1);}//開始進行對算術驗證碼表達式的拼接int num1 = (int) (Math.random() * 10 + 1);int num2 = (int) (Math.random() * 10 + 1);int fuhao = random.nextInt(3);//產生一個0-2之間的隨機整數//記錄符號String fuhaostr = null;int result = 0;switch (fuhao) {case 0:fuhaostr = "+";result = num1 + num2;break;case 1:fuhaostr = "-";result = num1 - num2;break;case 2:fuhaostr = "*";result = num1 * num2;break;}//拼接算術表達式,用戶圖片顯示String calc = num1 + " " + fuhaostr + " " + num2 + " = ?";//設置隨機顏色g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));//繪制表達式g.drawString(calc, 5, 25);//結束繪制try {//輸出圖片到頁面ImageIO.write(image, "jpg", response.getOutputStream());return String.valueOf(result);} catch (Exception e) {e.printStackTrace();return null;}}public static Color getRandomColor(int fc, int bc) {//利用隨機數Random random = new Random();//隨機顏色,了解顏色-Color(red,green,blue).rgb三元色0-255if (fc > 255) fc = 255;if (bc > 255) bc = 255;int r = fc + random.nextInt(bc - fc);int g = fc + random.nextInt(bc - fc);int b = fc + random.nextInt(bc - fc);return new Color(r, g, b);}}5.3.2注冊操作
本程序設計的權限管理中,支持學生的注冊賬號功能。若點擊注冊,則進行注冊的映射請求,輸入對應信息,進行注冊,所示選項全部為必填項,否則無法進行注冊,兩次輸入密碼會進行判斷,不同則注冊失敗。輸入的學號會事先判斷是否已經存在,存在則返回已存在。
?
圖6-3注冊界面
注冊部分代碼
Dao層:@Insert("insert into student(stdid, stdname, stdpassword, stdclass) value(#{stdid}, #{stdname}, #{stdpassword},#{stdclass})")public int insertStudent(Student student);//注冊用戶@Select("SELECT COUNT(stdid) from student where stdid=#{stdid}")public int findStudentExist(String stdid);//用戶id查看是否已經存在Controller層://注冊頁面顯示@RequestMapping("/register")public String registerUser() {return "register";}//注冊功能實現@RequestMapping(value = "/registerStudent", method = RequestMethod.POST)public String registerUser(Student student, HttpServletRequest request) throws Exception {if (!studentService.findStudentExist(student.getStdid())) {request.setAttribute("error", "用戶ID已經存在!");request.setAttribute("stdid", student.getStdid());request.setAttribute("stdname", student.getStdname());request.setAttribute("stdpassword", student.getStdpassword());request.setAttribute("stdclass", student.getStdclass());return "register";} else {studentService.register(student);}return "tips";}5.3.3后臺選擇操作
學生登錄完畢后,將會進入圖6-3-1所示的學生界面,學生可以查看個人信息,查看選課信息以及退課,修改密碼,查詢課設信息以及選課,成績查詢和報告的上傳,下載,預覽和刪除;教師登錄完畢后,將會進入圖6-3-2所示的教師界面,教師可以查看個人信息,查看自己的開課信息以及加課,修改密碼,查詢學生選擇課程的信息以及給出學生成績。
?
圖6-3-1 學生后臺界面
?
圖6-3-2教師后臺界面
5.3.4個人中心界面
點擊個人中心的下拉框后,進入如圖6-4-1的界面,通過session取出在登錄時存入的姓名密碼等信息,將查到的信息返回到前端界面進行展示。用戶可以點擊小眼睛查看自己的密碼。
關鍵代碼:
Dao層:@Select("SELECT * FROM `student`where stdname =#{stdname}")public Student findStudentByName(String stdname) throws IOException;//根據用戶id查找用戶Controller層:@RequestMapping("udentcenter")public?String?center(HttpSession?session)?throws?IOException?{String?stdname?=?(String)?session.getAttribute("studentname");Student?student?=?studentService.findStudentByName(stdname);session.setAttribute("stu",?student);return?"studentcenter"; }圖6-4學生個人中心界面
5.3.5學生課設中心界面
點擊課設中心下拉框,請求映射到對應的地址,通過登錄時存放的session,取出登錄用戶的id,調用service層函數,service層調用dao層的函數,操作數據庫取出所需的值,并存放在list集合中,返回該頁面。對于還沒出成績的課程,學生有權選擇推掉這門課設。同時點擊課設名可以查看課設的詳細信息,點擊組號可以查看小組的詳細信息。
主要代碼:
Dao層:@Select("SELECTquesion.queid,quesion.quename,teacher.teaname,choque.gruid,choque.score from quesion,teacher,choque\n" +"where quesion.queid = choque.queid ?and teacher.teaid = quesion.teaid and choque.stdid = #{stdid}")public List<ChooseCourseInfo> findChooseCourseInfo(String stdid);@Select("SELECT queid,quename,quemess FROM quesion where queid = #{queid}")public Quesion showcourse(String queid);@Select("SELECT `group`.grubody ,`group`.gruhead from `group` where gruid =#{gruid}")public Group showgroup(String gruid);Controller層:@RequestMapping("dcourse")public?String?stdcourse(HttpSession?session,?Model?model)?throws?IOException?{Student?stu?=?(Student)?session.getAttribute("stulogin");List<CourseInfo>?courseInfos?=?studentService.findCourseInfo(stu.getStdid());model.addAttribute("courseinfos",?courseInfos);return?"stdcourse";}@RequestMapping("owcourse")public?String?showcourse(String?queid,?Model?model)?throws?IOException?{Quesion?quesion?=?studentService.showcourse(queid);model.addAttribute("quesion",?quesion);return?"showcourse";}@RequestMapping("owgroup")public?String?showgroup(String?gruid,?Model?model)?throws?IOException?{Group?group?=?studentService.showgroup(gruid);model.addAttribute("group",?group);return?"showgroup";}?
圖6-5學生課設中心界面
5.3.6教師課設中心界面
點擊課設中心下拉框,請求映射到對應的地址,通過登錄時存放的session,取出登錄用戶的id,調用service層函數,service層調用dao層的函數,操作數據庫取出所需的值,并存放在list集合中,返回該頁面,教師還可以對已經添加的課設進行刪除,也可以通過點擊添加課程設計按鈕,輸入信息后,添加新的課程設計。
主要代碼:
Dao層:@Select("select quesion.queid,quesion.quename,\n" +"(select COUNT(*) from choque where choque.queid = quesion.queid) as stucount, \n" +"(SELECT COUNT(*) FROM choque where choque.queid = quesion.queid and choque.score<60) as passfail\n" +"FROM quesion WHERE teaid = #{teaid}")public List<TeacherCourse> findteachercourse(String teaid);@Insert("insert into quesion (queid, quename, quemess, teaid) VALUES (#{queid},#{quename},#{quemess},#{teaid}) ")@Delete("delete from quesion where queid= #{queid}")public void dlelete(String queid);public void insertteacourse(Quesion quesion);Controller層:@GetMapping("/topasscourse")public?String?topasscourse()?{return?"teachercourse";}@GetMapping("owcourse")@ResponseBodypublic?Map<String,?Object>?coursecenter(HttpSession?session,HttpServletRequest?request)?throws?IOException?{ Teacher?teacher?=?(Teacher)?session.getAttribute("tealogin"); List<TeacherCourse>?teacherCourses?=?teacherService.FindTeacherCourse(teacher.getTeaid());Map<String,?Object>?res?=?new?HashMap<>();res.put("code",?0);res.put("data",?teacherCourses);return?res;}@RequestMapping("/toaddcourse")public String toaddcou() {return "addteacourse";}@RequestMapping("/addteachercourse")@ResponseBodypublic Map<String, String> addcourse(Model model, HttpServletRequest request, Quesion quesion, HttpSession session) throws IOException {Teacher teacher = (Teacher) session.getAttribute("tealogin");System.out.println(quesion);Map<String, String> res = new HashMap<>();if (!teacherService.findqueexist(quesion.getQueid())) {res.put("code","200");res.put("msg", "課號已存在,不能重復添加");}else{quesion.setTeaid(teacher.getTeaid());teacherService.insertteacourse(quesion);res.put("code", "0");res.put("msg", "添加成功");}return res;}@RequestMapping("/delcourse")public String delcourse(String gruid) throws IOException {studentService.delcourse(gruid);return "redirect:coursecenter"; }?
圖6-6學生課設中心界面
5.3.7修改密碼界面
點擊修改密碼下拉框,請求映射到對應的地址,通過登錄時存放的session,取出登錄用戶的id,調用service層函數,service層調用dao層的函數,通過傳入的參數進行對學生信息的更新,頁面部分,系統會對輸入的信息進行判斷,包括原密碼和新密碼,判斷原密碼是否正確,判斷兩次輸入的密碼是否一致。
關鍵代碼:
Dao層@Update("UPDATE student set stdpassword = #{stdpassword} where stdid = #{stdid}")public int updatestudent(Student student);Controller層@RequestMapping("/pass")public String pass() {return "studentpass";}@RequestMapping("/topass")public String topass(String stdpassword, HttpSession session) throws IOException {Student stu = (Student) session.getAttribute("stulogin");String stdid = stu.getStdid();System.out.println(stdid + " " + stdpassword);Student studd = new Student();studd.setStdid(stdid);studd.setStdpassword(stdpassword);studentService.updateStudent(studd);return "redirect:tologin";}?
圖6-7管理員修改界面
5.3.8選課查詢界面
點擊選課查詢下拉框,請求映射到對應的地址,通過映射到JSP界面后,JSP界面通過Ajax異步請求,訪問映射地址,通過通過自定義的Json類將數據通過Json數據格式返回到JSP界面,以leyui渲染的數據表格形式展現出來。用戶可以對查出來的課設信息進行選擇,填寫同組成員信息后,將該課程設計加入到自己的課設中心。系統還會判斷收入的組號是不是已經存在,存在則返回改界面。
主要代碼:
Dao層:@Select("select * from quesion limit #{page},#{size}")public List<Quesion> FindQuesionByPage(Map<String, Object> params);//分頁查詢用戶@Select("select count(gruid) from ?`group` where gruid =#{gruid}")public int findGroupExist(String gruid);@Insert("insert into `group`(gruid, grubody, gruhead) VALUES (#{gruid},#{grubody},#{gruhead})")public int addgroup(Group group);@Insert("insert into choque(stdid, queid, gruid) VALUES (#{stdid},#{queid},#{gruid})")public int addchoque(Choque choque);@Select("SELECT COUNT(*) FROM quesion")public int count() throws SQLException;//查詢用戶總數Controller層:@RequestMapping(value = "/findquesionPage", method = RequestMethod.GET)public void findStudentPage(Quesion quesion, HttpServletRequest request, HttpServletResponse response) throws Exception {request.setCharacterEncoding("utf-8");response.setContentType("application/json;charset=UTF-8");//設置編碼,防止json中文亂碼int index = 1;String sindex = request.getParameter("page");if (sindex != null && !"".equals(sindex)) {index = Integer.parseInt(sindex);}int size = 5;String ssize = request.getParameter("limit");if (ssize != null && !"".equals(ssize)) {size = Integer.parseInt(ssize);}PageBean<Quesion> pageBean = new PageBean<Quesion>();pageBean.setLimit(size);pageBean.setPage(index);System.out.println(pageBean.getLimit());try {pageBean = studentService.FindQuesionByPage(index, size);} catch (IOException | SQLException e) {e.printStackTrace();}JsonResult<Quesion> jr = new JsonResult<Quesion>("0", "", String.valueOf(pageBean.getTotalCount()), pageBean.getList());//交互json格式所需的對象String jsonStr = JSON.toJSONString(jr);//將JsonResult對象轉換為json串PrintWriter out = response.getWriter();out.print(jsonStr);out.close();}@RequestMapping("/toaddcourse")public String addcoursejsp(String queid, Model model, HttpSession session) throws IOException {Student stud = (Student) session.getAttribute("stulogin");model.addAttribute("stqueid", queid);model.addAttribute("ststdid", stud.getStdid());return "addcourses";}@RequestMapping("/addinfo")public String addgroup(Model model, HttpServletRequest request, Group group, HttpSession session) throws IOException {String stdid = request.getParameter("stdid");String queid = request.getParameter("queid");System.out.println(stdid +" " + queid);if (!studentService.findGroupExist(group.getGruid())) {Student stud = (Student) session.getAttribute("stulogin");model.addAttribute("stqueid", queid);model.addAttribute("ststdid", stud.getStdid());request.setAttribute("gruid", "該組號已經存在");request.setAttribute("grubody", group.getGrubody());request.setAttribute("gruhead", group.getGruhead());return "addcourses";} else {Choque choque = new Choque();choque.setStdid(stdid);choque.setGruid(group.getGruid());choque.setQueid(queid);studentService.addgroup(group);studentService.addchoque(choque);return "tips";}}?
圖6-8-1?學生查看課設信息界面
?
圖6-8-2學生填寫同組信息添加課設界面
5.3.9成績查詢界面
點擊成績查詢下拉框,請求映射到對應的地址,獲取session中的用戶id后,調用service層的函數,在調用dao層的函數,通過數據庫查到的信息,封裝在一個list集合中返回到jsp界面。
主要代碼:
Dao層:@Select("SELECT quesion.queid,quesion.quename,teaname,score from quesion,teacher,choque \n" +"where quesion.queid=choque.queid and quesion.teaid = teacher.teaid and choque.stdid = #{stdid}")public List<CourseInfo> findCourseInfo(String stdid);Controller層:@RequestMapping("dcourse")public?String?stdcourse(HttpSession?session,?Model?model)?throws?IOException?{Student?stu?=?(Student)?session.getAttribute("stulogin");List<CourseInfo>?courseInfos?=?studentService.findCourseInfo(stu.getStdid());model.addAttribute("courseinfos",?courseInfos);return?"stdcourse";}圖6-9成績查詢界面
?
5.3.10文件上傳操作
用戶點擊文件上傳按鈕后,請求映射到對應的地址,通過異步Ajax請求,通過session中的id值,調用service層和dao層函數,查詢該用戶上傳的全部文件,封賬成一個list集合,最后封裝成Map映射,返回的jsp界面,通過layui table對于表格的渲染,展示數據。
主要代碼:
Dao層:@Select("SELECT * FROM `files` where files.stdid= #{stdid} order by files.stdid limit #{begin}, #{offset}")public List<UserFile> queryByUserId (@Param("stdid") String stdid , @Param("begin") Integer begin , @Param("offset") Integer offset);@Select("SELECT COUNT(files.stdid) FROM files where files.stdid = #{stdid}")public int queryFileCounts(String stdid);@Insert("insert into files(filename, ext, path, size, type, downcount, uploadtime, stdid)\n" +" VALUES (#{filename},#{ext},#{path},#{size},#{type},#{downcount},#{uploadtime},#{stdid});")public ?void savefile(UserFile userFile);@Delete(" delete from files where fileid=#{fileid}")public void delete(Integer fileid);@Select("select * FROM files where fileid =#{fileid}")public UserFile queryByUserFileId(Integer fileid);@Update("update files set downcount = #{downcount} where fileid = #{fileid}")public int updateflie(UserFile userFile);Controller層:// 展示所有的文件@GetMapping("/index")public String fileIndex() {return "filelist";}@PostMapping("showfiles")@ResponseBodypublic Map<String, Object> queryAllFile(HttpSession session, HttpServletRequest request) {int page = Integer.parseInt(request.getParameter("page"));int limit = Integer.parseInt(request.getParameter("limit"));Student student = (Student) session.getAttribute("stulogin");List<UserFile> userFiles = userFileService.queryByUserId(student.getStdid(), page, limit);Map<String, Object> res = new HashMap<>();res.put("code", 0);res.put("count", userFileService.queryFileCounts(student.getStdid()));res.put("data", userFiles);return res;}// 上傳文件到數據庫@PostMapping("upload")@ResponseBodypublic Map<String, String> uploadFile(@RequestParam("file") MultipartFile file, HttpSession session) {System.out.println("uploadFile trigger");Map<String, String> res = new HashMap<>();try {// 獲取上傳用戶的IdStudent student = (Student) session.getAttribute("stulogin");// 獲取文件的原始名稱String fileName = file.getOriginalFilename();// 獲取文件的后綴String extension = FilenameUtils.getExtension(file.getOriginalFilename());// 獲取文件的大小long size = file.getSize();// 獲取文件的類型String type = file.getContentType();// 根據日期動態的生成目錄String localContainer = "/fileContainer";String uploadPath = ResourceUtils.getURL("classpath").getPath() + localContainer;String dateFormat = new SimpleDateFormat("yyyy-MM-dd").format(new Date());File dateDirPath = new File(uploadPath + File.separator + dateFormat);if (!dateDirPath.exists()) {dateDirPath.mkdirs();}// 處理文件上傳file.transferTo(new File(dateDirPath, fileName));// 將文件信息存入數據庫中UserFile userFile = new UserFile();userFile.setFilename(fileName);userFile.setExt('.' + extension);userFile.setPath(Paths.get(localContainer, dateFormat, fileName).toString());userFile.setSize(size);userFile.setType(type);userFile.setStdid(student.getStdid());userFileService.save(userFile);res.put("code", "0");res.put("msg", "上傳成功");res.put("url", "index");} catch (IOException e) {e.printStackTrace();res.put("code", "-1");res.put("msg", "上傳失敗");res.put("url", "index");}return res;}@GetMapping("delete")@ResponseBodypublic Map<String, Object> delete(Integer fileid) {//@PathVariable:接收請求路徑中占位符的值Map<String, Object> map = new HashMap<>();try {UserFile fileInfo = userFileService.queryByUserFileId(fileid);final String realPath = ResourceUtils.getURL("classpath").getPath() + fileInfo.getPath();File file = new File(realPath);if (file.exists()) {file.delete(); ?//立即刪除}userFileService.delete(fileid);map.put("code", 0);map.put("msg", "刪除成功!");} catch (FileNotFoundException e) {e.printStackTrace();map.put("code", -1);map.put("msg", "刪除成功!");}return map;}public void getFile(String openStyle, Integer fileid, HttpServletResponse response) throws IOException {UserFile file = userFileService.queryByUserFileId(fileid);if(openStyle.equals("inline")){// 獲取文件信息final String realPath = ResourceUtils.getURL("classpath").getPath() + file.getPath();// 獲取文件輸入流FileInputStream is = new FileInputStream(new File(realPath));// 附件下載response.setHeader("content-disposition", openStyle+";filename=" + URLEncoder.encode(file.getFilename(), "UTF-8"));// 獲取響應response輸出流ServletOutputStream os = response.getOutputStream();// 文件拷貝IOUtils.copy(is, os);IOUtils.closeQuietly(is);IOUtils.closeQuietly(os);}// 更新下載次數if(openStyle.equals("attachment")){file.setDowncount(file.getDowncount() + 1);userFileService.update(file);}}@GetMapping("preview")public void preview(Integer fileid, HttpServletResponse response) throws IOException {String openStyle = "inline";getFile(openStyle,fileid,response);}@GetMapping("download")public void download( Integer fileid, HttpServletResponse response){String openStyle = "attachment";try{getFile(openStyle,fileid,response);} catch (IOException e) {e.printStackTrace();}}?
圖6-10-1文件界面
?
圖6-10-2文件上傳界面
?
圖6-10-3文件預覽界面
5.3.10教師端信息查詢
老師點擊信息查詢后,在session中獲取老師的信息,傳入controller層中,調用service和dao層函數,將得到的結果以封裝到list集合,將集合和一些其他信息一同封裝到map集合中,通過json串的形式一同傳回jsp界面,通過leyui table表格渲染展示。教師也可以對選擇了該課設的學生給出成績,也可以修改成績,方法類似,這里不再贅述。
主要代碼:
Dao層:@Select("SELECT student.stdid,student.stdname,quesion.queid,quesion.quename,choque.score\n" +"FROM student,choque,quesion\n" +"WHERE student.stdid = choque.stdid AND choque.queid = quesion.queid AND quesion.teaid = #{teaid}")public List<Studentlist> showstudent(String teaid);@Update("UPDATE choque SET score = #{score} WHERE stdid = #{stdid} AND queid = #{queid}")public void upscore(Studentlist studentlist);Controller層:@RequestMapping("owstudents")@ResponseBodypublic?Map<String,?Object>?showstudent(HttpSession?session,?Model?model)?throws?IOException?{Teacher?teacher?=?(Teacher)?session.getAttribute("tealogin");List<Studentlist>?studentlists?=?teacherService.showstudent(teacher.getTeaid());Map<String,?Object>?res?=?new?HashMap<>();res.put("code",?0);res.put("data",?studentlists);return?res;?}@RequestMapping("/addscore")@ResponseBodypublic?Map<String,?Object>?addscore(HttpSession?session,?Studentlist?studentlist)?throws?IOException?{teacherService.addscore(studentlist);Map<String,?Object>?res?=?new?HashMap<>();res.put("code",?0);res.put("msg",?"添加成功!");return?res;}?
圖6-11教師端信息查詢界面
?
圖6-12教師端條件查詢界面
5.3.11攔截器操作
登錄攔截器,默認攔截/student 路徑下的所有請求,若session中存在student,則放行,如不存在則跳轉到登錄界面。
public?class?LoginConfig?implements?WebMvcConfigurer?{@Overridepublic?void?addInterceptors(InterceptorRegistry?registry)?{//注冊TestInterceptor攔截器InterceptorRegistration?registration?=?registry.addInterceptor(new?LoginInterceptor());registration.addPathPatterns("/student/*");registration.excludePathPatterns("udent/tologin","udent/register","udent/registerStudent","udent/login","udent/code","/css/**","/images/**","/imagess/**","/js/**","/lib/**"?);}}@Override public?boolean?preHandle(HttpServletRequest?request,?HttpServletResponse?response,?Object?handler)?throws?Exception?{System.out.println("====================攔截前================="); HttpSession?session?=?request.getSession(); Student?user?=?(Student)?session.getAttribute("stulogin"); if?(user?!=?null)?{ System.out.println("====================用戶已登錄================="+user.toString()); return?true;} if?(!request.getContextPath().equals(request.getContextPath()?+?"student/tologin"))?{response.sendRedirect(request.getContextPath()?+?"udent/tologin");}return?false;項目完整源碼+說明書+軟件說明+數據庫表設計?:
點他:🍞正在為您運送作品詳情
總結
以上是生活随笔為你收集整理的SpringBoot + Servlet + Mybatis+ layui 学生选课管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器学习--岭回归10
- 下一篇: java信息管理系统总结_java实现科