后端技术包含springboot+mybatis+spring security+mysql+redis
前端技术包含 semanticUI + thymeleaf模板引擎
1. 下载项目之后 等待maven安装对应jar包
2. 自行下载redis 并按照资源包下的application.yml要求进行配置
3. 自行安装MySQL数据库 执行资源包下的sql文件
1. 运行redis服务器
2. 启动项目
3. 访问localhost:8080
4. 用户名:admin 密码:admin
若导出信息时报错,则需要设置mysql,设置方式如下:
SELECT @@sql_mode; 查看是否包含ONLY_FULL_GROUP_BY;若包含,则执行以下命令:
SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
执行完成后,再通过SELECT @@sql_mode; 来查看;
注意:该方法仅用于临时修改,重启mysql后,以上设置失效。
@RestController@RequestMapping("usercourse")@Apipublic class UserCourseController{ @Autowired UserCourseService userCourseService; @Autowired SelectableCourseDAO selectableCourseDAO; /** * 选课 * @param courseId * @param username * @return */ @PostMapping("choose") @PreAuthorize("hasAuthority('student')") public Object chooseCourse(@RequestParam("courseId") Integer courseId , @RequestParam("username") String username){ Map map = new HashMap<>(); try{ return userCourseService.chooseCourse(courseId , username); }catch(Exception e){ if(e instanceof DataIntegrityViolationException){ map.put("msg","该课程已经被抢完啦。"); }else{ map.put("msg","出现其他异常,选课失败!"); } map.put("flag",false); return JSON.toJSON(map); } } /** * 退课 * @param courseId * @param username * @return */ @PostMapping("cancel") @PreAuthorize("hasAuthority('student')") public Object cancelCourse(@RequestParam("courseId") Integer courseId , @RequestParam("username") String username){ return userCourseService.cancelCourse(courseId,username); } /** * 获取学生所选全部课程 * @param page * @param limit * @param username * @return */ @PostMapping("studentInfo") @PreAuthorize("hasAuthority('admin') or hasAuthority('student')") public Object studentInfo(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam("username")String username){ try{ Map map = new HashMap<>(); PageHelper.startPage(page , limit); List list = selectableCourseDAO.selectByUser(username); if(list == null){ return Msg.fail(); } //System.out.println("=="+username+"=="); PageInfo pageInfo = new PageInfo<>(list); map.put("totalPage" , pageInfo.getPages()); //总页数 map.put("totalCount" , pageInfo.getTotal()); //总条数 map.put("currentPage" , page); //当前页数。 map.put("data" , pageInfo.getList()); //获得的数据量 map.put("tCase",username); return JSON.toJSON(map); }catch(Exception e){ e.printStackTrace(); return Msg.fail(); } } //测试。 @PostMapping("cc") public Object cc(){ Map map = new HashMap<>(); try{ selectableCourseDAO.updateMinCourseStock(1); return true; }catch(Exception e){ if(e instanceof DataIntegrityViolationException){ map.put("msg","该课程已经被抢完啦。"); }else{ map.put("msg","出现其他异常,选课失败!"); } map.put("flag",false); return JSON.toJSON(map); } }} @RestController@RequestMapping("/course")@Apipublic class SelectableCourseController{ @Autowired SelectableCourseService selectableCourseService; /** * 获得全部课程 * @param page * @param limit * @param username * @return */ @PostMapping("/getAll") public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam(value = "username", required = false) String username){ return selectableCourseService.selectAll(page,limit,username); } /** * 根据课程类别搜索课程 * @param page * @param limit * @param username * @param type * @return */ @PostMapping("/getCourseByType") public Object getCourseByType(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam(value = "username", required = false) String username , @RequestParam("courseType") String type){ return selectableCourseService.selectCoursesByType(page,limit,type , username); } /** * 根据课程所属学院名称搜索课程 * @param page * @param limit * @param username * @param name * @return */ @PostMapping("/getCourseByCollege") public Object getCourseByCollege(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam(value = "username", required = false) String username , @RequestParam("college") String name){ return selectableCourseService.selectCoursesByCollege(page,limit,name , username); } /** * 根据课程名称模糊搜索课程 * @param page * @param limit * @param username * @param courseName * @return */ @PostMapping("selectByCourseName") public Object selectByCourseName(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam(value = "username", required = false) String username , @RequestParam("courseName") String courseName){ return selectableCourseService.selectByCourseName(page,limit,courseName , username); } /** * 根据课程剩余人数查找课程 * @param page * @param limit * @param username * @param count * @return */ @PostMapping("selectCourseByMemberCount") public Object selectByMemberCount(@RequestParam(value = "page", defaultValue = "1") int page , @RequestParam(value = "limit", defaultValue = "10") int limit , @RequestParam(value = "username", required = false) String username , @RequestParam("count") Integer count){ return selectableCourseService.selectCoursesByMemberCount(page,limit,count,username); } /** * 隐藏课程 * @param courseId * @return */ @PostMapping("hideBatch") @PreAuthorize("hasAuthority('admin')") public Object hideBatch(Integer courseId){ try{ return selectableCourseService.hideBatch(courseId); }catch(Exception e){ return Msg.msg("操作异常!"); } } @PostMapping("/addCourseByAdmin") @PreAuthorize("hasAuthority('admin')") public Object addCourse(@RequestParam("courseName")String courseName, @RequestParam("courseType")String courseType, @RequestParam("collegeId")Integer collegeId, @RequestParam("teacher")String teacher, @RequestParam("score")Integer score, @RequestParam("stock")Integer stock, @RequestParam("address")String address, @RequestParam(value = "description",defaultValue = "")String description){ try{ return selectableCourseService.addCourse(courseName,collegeId,courseType,teacher,score,stock,address,description); }catch(Exception e){ e.printStackTrace(); return Msg.msg("出现异常,添加课程失败!"); } }}@Controller@Apipublic class AdminController{ @Autowired AdminService adminService; /** * Excel表格导出接口 * http://localhost:8080/ExcelDownload * @param response response对象 */ @GetMapping("/ExcelDownload") @PreAuthorize("hasAuthority('admin')") public void excelDownload(HttpServletResponse response) throws IOException{ adminService.excelOut(response); } /** * 课程管理 * @return */ @GetMapping("/courseManage") @PreAuthorize("hasAnyAuthority('admin')") public String courseManage(){ return "courseManage"; } /** * 添加课程 * @return */ @GetMapping("/addCourse") @PreAuthorize("hasAuthority('admin')") public String addCourse(){ return "addCourse"; }}@Controller@Apipublic class LoginController{ @Autowired AdminService adminService; @Autowired UserService userService; @RequestMapping("/login") public String login(){ return "login"; } @GetMapping("/") public String index() { return "success"; } @GetMapping("/manager") @PreAuthorize("hasAuthority('admin')") public String manager(){ return "manager"; } //@RequestMapping("/error") //public String error(){ // return "error"; //} @GetMapping("/info") @PreAuthorize("hasAuthority('student')") public String info(){ return "studentInfo"; } @GetMapping("/getCode") @ResponseBody public Object getCode(HttpServletRequest request) { /* 生成验证码字符串 */ String verifyCode = VerifyCodeUtil.generateVerifyCode(4); String uuid = UUIDUtil.GeneratorUUIDOfSimple(); HttpSession session = request.getSession(); session.setAttribute(uuid,verifyCode); //将验证码与生成的uuid绑定在一起 System.out.println("生成的验证码为:" + verifyCode); int width = 111,height = 36; try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { VerifyCodeUtil.outputImage(width, height, stream, verifyCode); return Msg.msg("data",new ImgVO("data:image/gif;base64,"+ Base64Utils.encodeToString(stream.toByteArray()),uuid)); } catch (IOException e) { e.printStackTrace(); } return null; } public User getUser() { //为了session从获取用户信息,可以配置如下 User user = new User(); SecurityContext ctx = SecurityContextHolder.getContext(); Authentication auth = ctx.getAuthentication(); if (auth.getPrincipal() instanceof UserDetails) user = (User) auth.getPrincipal(); return user; } public HttpServletRequest getRequest() { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); }} | 留言与评论(共有 0 条评论) “” |