Java實(shí)戰(zhàn)之課程在線學(xué)習(xí)系統(tǒng)的實(shí)現(xiàn)
一、前言
項(xiàng)目介紹
采用SpringBoot+Spring+Mybatis+Thyeleaf實(shí)現(xiàn)的在線學(xué)習(xí)系統(tǒng),一共2個(gè)身份。
管理員登錄系統(tǒng)后可以管理所有用戶信息,管理角色信息,添加修改管理課件信息,學(xué)生學(xué)習(xí)培訓(xùn)批次管理,成績(jī)導(dǎo)入管理
學(xué)生登錄系統(tǒng)后可以查詢自己的個(gè)人信息,查詢課件列表學(xué)習(xí),查詢我的培訓(xùn)記錄,查詢自己的成績(jī)
采用SpringBoot框架實(shí)現(xiàn) 前臺(tái)模板用的thymeleaf 數(shù)據(jù)庫(kù)層采用mybatis框架 注解模式
upload文件夾放入D盤根目錄!
項(xiàng)目運(yùn)行
登錄地址: http://localhost:8080/th/login
管理員賬號(hào)和密碼: admin admin
學(xué)生登錄賬號(hào): 1314 密碼: 123456
二、效果圖展示
三、核心代碼
用戶管理控制層
@Controller @RequestMapping("/User") public class UserController { @Autowired private UserService userService; @Autowired private PowerService powerService; @Autowired private RoleService roleService; @Autowired private NoticeService noticeService; @RequestMapping("/Main") public String res(HttpServletRequest request){ String time = DateUtil.getStringToday(); request.getSession().setAttribute("time", time); Notice notice = new Notice(); List<Notice> list = noticeService.queryAll(notice); notice = list.get(0); User user = userService.selectByPrimaryKey(notice.getUserid()); notice.setUserid(user.getName()); request.getSession().setAttribute("notice", notice); return "Main"; } @RequestMapping("/changePa") public String res1(){ return "changePass"; } @RequestMapping("/Login") public ModelAndView login(HttpServletRequest request,String id,String password) throws Exception{ ModelAndView mav = new ModelAndView(); User user1 = userService.selectByPrimaryKey(id); if(user1 == null || !password.equals(user1.getPassword())){ mav.setViewName("index"); request.getSession().setAttribute("info", "error"); return mav; }else{ Role role = new Role(); role.setRoleid(user1.getRoleid()); List<Role> list =roleService.QueryAll(role); role =list.get(0); request.getSession().setAttribute("roleName", role.getRolename()); Power power = powerService.selectByPrimaryKey(role.getPowerid()); if(!StringUtil.isNullOrEmpty(power.getPower())){ request.getSession().setAttribute("power", power.getPower()); } String time = DateUtil.getStringToday(); request.getSession().setAttribute("time", time); request.getSession().setAttribute("user", user1); mav.setViewName("redirect:/User/Main"); } return mav; } @RequestMapping("/updateStudent") public String update(User user){ userService.updateByPrimaryKey(user); return "redirect:/User/student"; } @RequestMapping("/updateTeacher") public String updatet(User user){ userService.updateByPrimaryKey(user); return "redirect:/User/teacher"; } @RequestMapping("/updatePa") public String updatePa(String userID,String password){ User user = new User(); System.out.println(userID); User user1 = userService.selectByPrimaryKey(userID); user1.setPassword(password); userService.updateByPrimaryKey(user1); return "Main"; } @RequestMapping("/delete") public String delete(String ID){ userService.deleteByPrimaryKey(ID); return "redirect:/User/queryAll"; } @RequestMapping("/teacher") public String QueryAllTeacher(HttpServletRequest request,User user){ List<User> list = userService.QueryAllTeacher(user); request.setAttribute("list", list); if(null != user.getName()){ request.setAttribute("name", user.getName()); } if(null != user.getMobile()){ request.setAttribute("mobile", user.getMobile()); } return "teacher"; } @ResponseBody @RequestMapping("/jsonteacher") public String QueryAllTeacherjson(HttpServletRequest request,User user){ List<User> list = userService.QueryAllTeacher(user); JSONObject json = new JSONObject(); return json.toJSONString(list); } @RequestMapping("/student") public String QueryAllStudent(HttpServletRequest request,User user){ List<User> list = userService.QueryAllStudent(user); request.setAttribute("list", list); if(null != user.getName()){ request.setAttribute("name", user.getName()); } if(null != user.getMobile()){ request.setAttribute("mobile", user.getMobile()); } return "student"; } @RequestMapping("/addteacher") public String addUser(User user){ String passWord = "123456"; user.setPassword(passWord); user.setType(Constans.TEACHER); userService.insert(user); return "redirect:/User/teacher"; } @RequestMapping("/addstudent") public String addStudent(User user){ String passWord = "123456"; user.setPassword(passWord); user.setType(Constans.STUDENT); userService.insert(user); return "redirect:/User/student"; } @ResponseBody @RequestMapping("/queryOne") public String queryOne(String ID){ User user = new User(); user.setId(ID); List<User> list = userService.QueryAll(user); user = list.get(0); JSONObject json = new JSONObject(); String data = json.toJSONString(user); return data; } @RequestMapping("/quit") public ModelAndView quit(HttpServletRequest request) throws Exception{ ModelAndView mav = new ModelAndView(); HttpSession session1 = request.getSession(); session1.invalidate(); request.getSession().setAttribute("info", "quit"); mav.setViewName("index"); return mav; } }
角色管理控制層
@Controller @RequestMapping("/Role") public class RoleController { @Autowired private RoleService depotService; @Autowired private PowerService powerService; @RequestMapping("/update") public String update(String id,String rolename,String powerContent){ Role role = new Role(); role.setRoleid(id); role.setRolename(rolename); depotService.update(role); List<Role> list = depotService.QueryAll(role); Role role1 = list.get(0); Power power = new Power(); if(powerContent.indexOf("110") != -1){ powerContent = powerContent + ",1100"; } if(powerContent.indexOf("120") != -1){ powerContent = powerContent + ",1200"; } if(powerContent.indexOf("130") != -1){ powerContent = powerContent + ",1300"; } if(powerContent.indexOf("140") != -1){ powerContent = powerContent + ",1400"; } if(powerContent.indexOf("150") != -1){ powerContent = powerContent + ",1500"; } power.setPower(powerContent); power.setRoleid(role1.getPowerid()); powerService.update(power); return "redirect:/Role/queryAll"; } @RequestMapping("/delete") public String delete(String ID){ depotService.deleteByPrimaryKey(ID); return "redirect:/Role/queryAll"; } @RequestMapping("/queryAll") public String queryAll(HttpServletRequest request,Role role){ List<Role> list = depotService.QueryAll(role); request.setAttribute("list", list); if(null != role.getRolename()){ request.setAttribute("rolename", role.getRolename()); } return "Role"; } @RequestMapping("/add") public String add(String roleid,String rolename,String powerContent){ Power power1 = new Power(); Role role = new Role(); String powerid = String.valueOf(Math.random()).substring(2, 8); role.setRoleid(String.valueOf(Math.random()).substring(2, 6)); role.setPowerid(powerid); role.setRolename(rolename); power1.setPower(powerContent); power1.setRoleid(powerid); power1.setId(String.valueOf(Math.random()).substring(2, 8)); powerService.insert(power1); depotService.insert(role); return "redirect:/Role/queryAll"; } @ResponseBody @RequestMapping("/queryOne") public String queryOne(String ID){ JSONObject json = new JSONObject(); Role depot = new Role(); Power power = new Power(); power.setId(ID); System.out.println(ID); depot.setRoleid(ID); List<Role> list = depotService.QueryAll(depot); Role role1 = list.get(0); Power power1 = powerService.selectByPrimaryKey(role1.getPowerid()); String name = role1.getRolename(); role1.setPowerid(power1.getPower()); String data = json.toJSONString(role1); return data; } @ResponseBody @RequestMapping("/getAll") public String getAll(Role role){ JSONObject json = new JSONObject(); List<Role> list = depotService.QueryAll(role); String jsonq = json.toJSONString(list); System.out.println(jsonq); return jsonq; } }
課程管理控制層
@Controller @RequestMapping("/Course") public class CourseController { @Autowired private CourseService courseService; @Autowired private CurelationService curelationService; @Autowired private CoursecommentService coursecommentService; @ResponseBody @RequestMapping("/queryOneCom") public String queryOneCom(String ID){ Coursecomment course = new Coursecomment(); course.setId(ID); System.out.println("===================================="+ID); List<Coursecomment> list = coursecommentService.queryAll(course); course = list.get(0); JSONObject json = new JSONObject(); return json.toJSONString(course); } @RequestMapping("addComment") public String addComment(HttpServletRequest request, Coursecomment coursecomment){ User user = (User) request.getSession().getAttribute("user"); coursecomment.setCreatetime(DateUtil.getStringToday()); coursecomment.setUserid(user.getName()); coursecomment.setId(String.valueOf(Math.random()).substring(2,10)); coursecommentService.insert(coursecomment); return "redirect:/Course/suggeetion"; } @ResponseBody @RequestMapping("jsoncourse") public String jsoncourse(HttpServletRequest request, Curelation course){ User user = (User) request.getSession().getAttribute("user"); /*String type = "1"; if ("1".equals(user.getType())){ type="2"; } course.setType(type); course.setUserid(user.getId());*/ List<Curelation> curelationList = curelationService.queryAll(course); List<Course> dataList = new ArrayList<>(); for (int i = 0; i < curelationList.size(); i++) { Course curelation = courseService.selectByPrimaryKey(curelationList.get(i).getCourseid()); dataList.add(curelation); } JSONObject json = new JSONObject(); return json.toJSONString(dataList); } @RequestMapping("suggeetion") public String suggeetion(HttpServletRequest request, Coursecomment coursecomment){ List<Coursecomment> coursecomments = coursecommentService.queryAll(coursecomment); request.setAttribute("list",coursecomments); return "suggeetion"; } @RequestMapping("view") public String view(HttpServletRequest request){ User user = (User) request.getSession().getAttribute("user"); String type = "1"; if ("1".equals(user.getType())){ type="2"; } List<Map<String,String>> list=curelationService.courseview(type,user.getId()); request.setAttribute("list",list); return "courseview"; } @RequestMapping("deletecomment") public String deletecomment(String ID){ coursecommentService.deleteByPrimaryKey(ID); return "redirect:/Course/suggeetion"; } @RequestMapping("queryAll") public String queryAll(HttpServletRequest request, Course course){ List<Course> list = courseService.queryAll(course); request.setAttribute("list",list); return "course"; } @RequestMapping("/receive") public String receive(HttpServletRequest request, HttpServletResponse response, MultipartFile file){ try { //也可以用request獲取上傳文件 //MultipartFile fileFile = request.getFile("file"); //這里是頁面的name屬性 //轉(zhuǎn)換成輸入流 InputStream is = file.getInputStream(); //得到excel Workbook workbook = Workbook.getWorkbook(is); //得到sheet Sheet sheet = workbook.getSheet(0); //得到列數(shù) int colsNum = sheet.getColumns(); //得到行數(shù) int rowsNum = sheet.getRows(); //單元格 Cell cell; Cell cell1; List<Map> list = new ArrayList<>(); Map<Integer, String> map = new HashMap<Integer, String>(); for (int i = 1; i < rowsNum; i++) {//我的excel第一行是標(biāo)題,所以 i從1開始 cell = sheet.getCell(0,i); cell1 = sheet.getCell(5,i); Curelation curelation = new Curelation(); curelation.setId(cell.getContents()); curelation.setScore(cell1.getContents()); curelationService.updateByPrimaryKey(curelation); } } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { e.printStackTrace(); } return "redirect:/Course/queryCourse"; } @RequestMapping("/queryCourse") public String queryScore(HttpServletRequest request,Curelation curelation){ curelation.setType("1"); List<Curelation> list = curelationService.queryAll(curelation); request.setAttribute("list",list ); return "ScoreList"; } @RequestMapping("/teacher") public String teacher(HttpServletRequest request){ User user = (User) request.getSession().getAttribute("user"); Course course = new Course(); course.setCourseteacher(user.getName()); List<Course> courseList = courseService.queryAll(course); request.setAttribute("list",courseList); return "teacherDeal"; } @RequestMapping("/student") public String student(HttpServletRequest request){ Course course = new Course(); course.setStatus("1"); List<Course> courseList = courseService.queryAll(course); request.setAttribute("list",courseList); return "studentChoose"; } @RequestMapping("/upload") public String upload(){ return "uploadScore"; } @RequestMapping("/Export") public void Export(HttpServletResponse response, User user){ response.setContentType("application/binary;charset=UTF-8"); try { ServletOutputStream out = response.getOutputStream(); String fileName1 = "學(xué)生信息"; String fileName2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()); String fileName = fileName1+fileName2; response.setHeader("Content-disposition", "attachment; filename=" +new String(fileName.getBytes("gbk"),"iso8859-1") + ".xls"); String[] titles = { "成績(jī)編號(hào)","學(xué)生編號(hào)", "學(xué)生姓名", "課程編號(hào)", "課程名稱", "成績(jī)" }; courseService.export(titles, out,user); } catch (Exception e) { e.printStackTrace(); } } @RequestMapping("delete") public String delete(String ID){ courseService.deleteByPrimaryKey(ID); return "redirect:/Course/queryAll"; } @RequestMapping("update") public String update(Course course){ courseService.updateByPrimaryKey(course); return "redirect:/Course/queryAll"; } @Transactional @RequestMapping("update1") public String update1(HttpServletRequest request,Course course){ course.setStatus("1"); courseService.updateByPrimaryKey(course); User user = (User) request.getSession().getAttribute("user"); Curelation curelation1 = new Curelation(); curelation1.setCourseid(course.getId()); curelation1.setUserid(user.getId()); List<Curelation> curelationList = curelationService.queryAll(curelation1); if(curelationList.size()==0){ Curelation curelation = new Curelation(); curelation.setUserid(user.getId()); curelation.setCourseid(course.getId()); curelation.setId(String.valueOf(Math.random()).substring(2, 10)); curelation.setType("2"); curelationService.insert(curelation); } return "redirect:/Course/teacher"; } @RequestMapping("update2") public String update2(HttpServletRequest request,Course course){ User user = (User) request.getSession().getAttribute("user"); Curelation curelation = new Curelation(); curelation.setUserid(user.getId()); curelation.setCourseid(course.getId()); List<Curelation> curelationList = curelationService.queryAll(curelation); if(curelationList.size() == 0){ curelation.setId(String.valueOf(Math.random()).substring(2, 10)); curelation.setType("1"); curelationService.insert(curelation); }else{ Curelation curelation1 = curelationList.get(0); curelation1.setUserid(user.getId()); curelation1.setCourseid(course.getId()); System.out.println(curelation1.toString()); curelationService.updateByPrimaryKey(curelation1); } return "redirect:/Course/student"; } @ResponseBody @RequestMapping("/queryOne") public String queryOne(String ID){ Course course = new Course(); course.setId(ID); List<Course> list = courseService.queryAll(course); course = list.get(0); JSONObject json = new JSONObject(); return json.toJSONString(course); } @RequestMapping("add") public String addCourse(Course course){ course.setId(String.valueOf(Math.random()).substring(2, 10)); System.out.println(course.toString()); courseService.insert(course); return "redirect:/Course/queryAll"; } }
以上就是Java實(shí)戰(zhàn)之課程在線學(xué)習(xí)系統(tǒng)的實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Java課程在線學(xué)習(xí)系統(tǒng)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SpringBoot使用@Cacheable注解實(shí)現(xiàn)緩存功能流程詳解
最近一直再學(xué)Spring Boot,在學(xué)習(xí)的過程中也有過很多疑問。為了解答自己的疑惑,也在網(wǎng)上查了一些資料,以下是對(duì)@Cacheable注解的一些理解2023-01-01rabbitmq的消息持久化處理開啟,再關(guān)閉后,消費(fèi)者啟動(dòng)報(bào)錯(cuò)問題
這篇文章主要介紹了rabbitmq的消息持久化處理開啟,再關(guān)閉后,消費(fèi)者啟動(dòng)報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11Java后端長(zhǎng)時(shí)間無操作自動(dòng)退出的實(shí)現(xiàn)方式
這篇文章主要介紹了Java后端長(zhǎng)時(shí)間無操作自動(dòng)退出的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01java實(shí)現(xiàn)監(jiān)控rtsp流轉(zhuǎn)flv方法實(shí)例(前端播放,前后端代碼都有)
這篇文章主要給大家介紹了關(guān)于java實(shí)現(xiàn)監(jiān)控rtsp流轉(zhuǎn)flv的相關(guān)資料,文中介紹的是前端播放,前后端代碼都有,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06Spring框架構(gòu)造注入操作實(shí)戰(zhàn)案例
這篇文章主要介紹了Spring框架構(gòu)造注入操作,結(jié)合具體實(shí)例形式分析了spring框架構(gòu)造輸入的相關(guān)定義與使用操作技巧,需要的朋友可以參考下2019-11-11IDEA插件之Mybatis Log plugin 破解及安裝方法
這篇文章主要介紹了IDEA插件之Mybatis Log plugin 破解方法及安裝方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09SpringBoot啟動(dòng)后立即執(zhí)行的幾種方法小結(jié)
在項(xiàng)目開發(fā)中某些場(chǎng)景必須要用到啟動(dòng)項(xiàng)目后立即執(zhí)行方式的功能,本文主要介紹了SpringBoot啟動(dòng)后立即執(zhí)行的幾種方法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2023-05-05