Java项目:学生选课管理系统(java+SpringBoot+Mybatis-plus+Thymeleaf+mysql)

Posted pastclouds

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java项目:学生选课管理系统(java+SpringBoot+Mybatis-plus+Thymeleaf+mysql)相关的知识,希望对你有一定的参考价值。

源码获取:博客首页 "资源" 里下载!

系统主要有以下功能:选课管理、教评管理、班级管理、年级管理、专业管理、系部管理、教师授课管理、录入教师、学生管理、学生选课管理、退学管理、退选管理、课目管理、成绩管理、新闻管理、系统管理等

主要有三个角色: 管理员、学生、教师。

管理员后台账号:admin 密码:123456

学生账号:student表 密码是身份后6位 (教师同样)

运行环境:windows/Linux均可、jdk1.8、mysql5.7、idea/eclipse均可。

 

 

 

 

用户管理控制层:

@Controller
@RequestMapping("admin/system/user")
public class UserController 

    @Autowired
    UserService userService;

    @Autowired
    RoleService roleService;

    @Autowired
    UploadService uploadService;

    @RequestMapping("list")
    @SysLog("跳转系统用户列表页面")
    public String list()
        return "admin/user/list";
    

    @RequiresPermissions("sys:user:list")
    @PostMapping("list")
    @ResponseBody
    public PageData<User> list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                               @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                               ServletRequest request)
        Map map = WebUtils.getParametersStartingWith(request, "s_");
        PageData<User> userPageData = new PageData<>();
        QueryWrapper<User> userWrapper = new QueryWrapper<>();
        if(!map.isEmpty())
            String type = (String) map.get("type");
            if(StringUtils.isNotBlank(type)) 
                userWrapper.eq("is_admin", "admin".equals(type) ? true : false);
            
            String keys = (String) map.get("key");
            if(StringUtils.isNotBlank(keys)) 
                userWrapper.and(wrapper -> wrapper.like("login_name", keys).or().like("tel", keys).or().like("email", keys));
            
        
        IPage<User> userPage = userService.page(new Page<>(page,limit),userWrapper);
        userPageData.setCount(userPage.getTotal());
        userPageData.setData(userPage.getRecords());
        return userPageData;
    

    @RequestMapping("add")
    public String add(ModelMap modelMap)
        List<Role> roleList = roleService.selectAll();
        modelMap.put("roleList",roleList);
        return "admin/user/add";
    

    @RequiresPermissions("sys:user:add")
    @PostMapping("add")
    @ResponseBody
    @SysLog("保存新增系统用户数据")
    public ResponseEntity add(@RequestBody  User user)
        if(StringUtils.isBlank(user.getLoginName()))
            return ResponseEntity.failure("登录名不能为空");
        
        if(user.getRoleLists() == null || user.getRoleLists().size() == 0)
            return  ResponseEntity.failure("用户角色至少选择一个");
        
        if(userService.userCount(user.getLoginName())>0)
            return ResponseEntity.failure("登录名称已经存在");
        
//        if(StringUtils.isNotBlank(user.getEmail()))
//            if(userService.userCount(user.getEmail())>0)
//                return ResponseEntity.failure("该邮箱已被使用");
//            
//        
//        if(StringUtils.isNoneBlank(user.getTel()))
//            if(userService.userCount(user.getTel())>0)
//                return ResponseEntity.failure("该手机号已被绑定");
//            
//        
        //设置默认密码
        if(StringUtils.isBlank(user.getPassword()))
            user.setPassword(Constants.DEFAULT_PASSWORD);
        
        userService.saveUser(user);
        if(StringUtils.isBlank(user.getId()))
            return ResponseEntity.failure("保存用户信息出错");
        
        //保存用户角色关系
        userService.saveUserRoles(user.getId(),user.getRoleLists());
        return ResponseEntity.success("操作成功");
    

    @RequestMapping("edit")
    public String edit(String id,ModelMap modelMap)
        User user = userService.findUserById(id);
        String roleIds = "";
        if(user != null) 
            roleIds = user.getRoleLists().stream().map(role -> role.getId()).collect(Collectors.joining(","));
        
        List<Role> roleList = roleService.selectAll();
        modelMap.put("localuser",user);
        modelMap.put("roleIds",roleIds);
        modelMap.put("roleList",roleList);
        return "admin/user/edit";
    

    @RequiresPermissions("sys:user:edit")
    @PostMapping("edit")
    @ResponseBody
    @SysLog("保存系统用户编辑数据")
    public ResponseEntity edit(@RequestBody  User user)
        if(StringUtils.isBlank(user.getId()))
            return ResponseEntity.failure("用户ID不能为空");
        
        if(StringUtils.isBlank(user.getLoginName()))
            return ResponseEntity.failure("登录名不能为空");
        
        if(user.getRoleLists() == null || user.getRoleLists().size() == 0)
            return  ResponseEntity.failure("用户角色至少选择一个");
        
        User oldUser = userService.findUserById(user.getId());
        if(StringUtils.isNotBlank(user.getEmail()))
            if(!user.getEmail().equals(oldUser.getEmail()))
                if(userService.userCount(user.getEmail())>0)
                    return ResponseEntity.failure("该邮箱已被使用");
                
            
        
        if(StringUtils.isNotBlank(user.getLoginName()))
            if(!user.getLoginName().equals(oldUser.getLoginName())) 
                if (userService.userCount(user.getLoginName()) > 0) 
                    return ResponseEntity.failure("该登录名已存在");
                
            
        
        if(StringUtils.isNotBlank(user.getTel()))
            if(!user.getTel().equals(oldUser.getTel())) 
                if (userService.userCount(user.getTel()) > 0) 
                    return ResponseEntity.failure("该手机号已经被绑定");
                
            
        
        user.setIcon(oldUser.getIcon());
        userService.updateUser(user);

        if(StringUtils.isBlank(user.getId()))
            return ResponseEntity.failure("保存用户信息出错");
        
        userService.saveUserRoles(user.getId(),user.getRoleLists());
        return ResponseEntity.success("操作成功");
    

    @RequiresPermissions("sys:user:lock")
    @PostMapping("lock")
    @ResponseBody
    @SysLog("锁定或开启系统用户")
    public ResponseEntity lock(@RequestParam(value = "id",required = false)String id)
        if(StringUtils.isBlank(id))
            return ResponseEntity.failure("参数错误");
        
        User user = userService.getById(id);
        if(user == null)
            return ResponseEntity.failure("用户不存在");
        
        userService.lockUser(user);
        return ResponseEntity.success("操作成功");
    

    @RequiresPermissions("sys:user:delete")
    @PostMapping("delete")
    @ResponseBody
    @SysLog("删除系统用户数据(单个)")
    public ResponseEntity delete(@RequestParam(value = "id",required = false)String id)
        if(StringUtils.isBlank(id))
            return ResponseEntity.failure("参数错误");
        
        User user = userService.getById(id);
        if(user == null)
            return ResponseEntity.failure("用户不存在");
        else if(user.getAdminUser()) 
            return ResponseEntity.failure("不能删除后台用户");
        
        userService.deleteUser(user);
        return ResponseEntity.success("操作成功");
    

    @RequiresPermissions("sys:user:delete")
    @PostMapping("deleteSome")
    @ResponseBody
    @SysLog("删除系统用户数据(多个)")
    public ResponseEntity deleteSome(@RequestBody List<User> users)
        if(users == null || users.size()==0)
            return ResponseEntity.failure("请选择需要删除的用户");
        
        for (User u : users)
            if(u.getAdminUser())
                return ResponseEntity.failure("不能删除超级管理员");
            else
                userService.deleteUser(u);
            
        
        return ResponseEntity.success("操作成功");
    

    @RequestMapping("userinfo")
    public String toEditMyInfo(ModelMap modelMap)
        String userId = MySysUser.id();
        User user = userService.findUserById(userId);
        modelMap.put("userinfo",user);
        modelMap.put("userRole",user.getRoleLists());
        return "admin/user/userInfo";
    

    @SysLog("系统用户个人信息修改")
    @PostMapping("saveUserinfo")
    @ResponseBody
    public ResponseEntity saveUserInfo(User user)
        if(StringUtils.isBlank(user.getId()))
            return ResponseEntity.failure("用户ID不能为空");
        
        if(StringUtils.isBlank(user.getLoginName()))
            return ResponseEntity.failure("登录名不能为空");
        
        User oldUser = userService.findUserById(user.getId());
        if(StringUtils.isNotBlank(user.getEmail()))
            if(!user.getEmail().equals(oldUser.getEmail()))
                if(userService.userCount(user.getEmail())>0)
                    return ResponseEntity.failure("该邮箱已被使用");
                
            
        
        if(StringUtils.isNotBlank(user.getTel()))
            if(!user.getTel().equals(oldUser.getTel())) 
                if (userService.userCount(user.getTel()) > 0) 
                    return ResponseEntity.failure("该手机号已经被绑定");
                
            
        
        userService.updateById(user);
        return ResponseEntity.success("操作成功");
    

    @RequestMapping("changePassword")
    public String changePassword(ModelMap modelMap)
        modelMap.put("currentUser",userService.getById(MySysUser.id()));
        return "admin/user/changePassword";
    
    @CrossOrigin
    @SysLog("用户修改密码")
    @PostMapping("changePassword")
    @ResponseBody
    public ResponseEntity changePassword(@RequestParam(value = "userName",required = false)String userName,
                                         @RequestParam(value = "oldPwd",required = false)String oldPwd,
                                       @RequestParam(value = "newPwd",required = false)String newPwd,
                                       @RequestParam(value = "confirmPwd",required = false)String confirmPwd)
        if(StringUtils.isBlank(oldPwd))
            return ResponseEntity.failure("旧密码不能为空");
        
        if(StringUtils.isBlank(newPwd))
            return ResponseEntity.failure("新密码不能为空");
        
        if(StringUtils.isBlank(confirmPwd))
            return ResponseEntity.failure("确认密码不能为空");
        
        if(!confirmPwd.equals(newPwd))
            return ResponseEntity.failure("确认密码与新密码不一致");
        
        //小程序修改密码
        if(StringUtils.isBlank(userName))
            //PC修改密码
            User user = userService.findUserById(MySysUser.id());

            byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
            String password = Encodes.encodeHex(hashPassword);

            if(!user.getPassword().equals(password))
                return ResponseEntity.failure("旧密码错误");
            
            user.setPassword(newPwd);
            Encodes.entryptPassword(user);
            userService.updateById(user);
            return ResponseEntity.success("操作成功");
        else 
            //小程序修改密码
            User user = userService.findUserByLoginName(userName);

            byte[] hashPassword = Encodes.sha1(oldPwd.getBytes(), Encodes.SHA1, Encodes.decodeHex(user.getSalt()), Constants.HASH_INTERATIONS);
            String password = Encodes.encodeHex(hashPassword);

            if(!user.getPassword().equals(password))
                return ResponseEntity.failure("旧密码错误");
            
            user.setPassword(newPwd);
            Encodes.entryptPassword(user);
            userService.updateById(user);
            return ResponseEntity.success("操作成功");
        

    

    @SysLog("上传头像")
    @PostMapping("uploadFace")
    @ResponseBody
    public ResponseEntity uploadFile(@RequestParam("icon") MultipartFile file, HttpServletRequest httpServletRequest) 
        if(file == null)
            return ResponseEntity.failure("上传文件为空 ");
        
        String url = null;
        Map map = new HashMap();
        try 
            url = uploadService.upload(file);
            map.put("url", url);
            map.put("name", file.getOriginalFilename());
         catch (Exception e) 
            e.printStackTrace();
            return ResponseEntity.failure(e.getMessage());
        
        return ResponseEntity.success("操作成功").setAny("data",map);
    


学生管理控制层:

@Controller
public class StudentController extends BaseController 
    @Autowired
    private StudentService studentService;

    // 跳转学生查询页面
    @RequestMapping("/selectStudent")
    public String selectStudent()
        return "view/student/selStudent";
    


    //  查询所有学生
    @RequestMapping("selStudent")
    @ResponseBody
    public LayuiResult<Map> selectStu(pageCount pageCount, StudentVO studentVO)
        LayuiResult<Map> result = new LayuiResult<>();
        List<Map> list = studentService.selStudent(studentVO,pageCount);
        int count = studentService.selCount(studentVO);
        result.setData(list);
        result.setCount(count);
        return result;
    

    //  查询所有专业
    @RequestMapping("selDepartment")
    @ResponseBody
    public LayuiResult<Map> selDepartment()
        List<DepartmentDB> selDepartment = studentService.selDepartment();
        LayuiResult result = new LayuiResult();
        result.setData(selDepartment);
        return result;
    

    //  根据系部查询专业
    @RequestMapping("selectdid")
    @ResponseBody
    public LayuiResult<Map> selMajorDB(Integer did)
        List<MajorDB> major  =studentService.selMajorDB(did);
        LayuiResult result = new LayuiResult();
        result.setData(major);
        return result;
    
    //  根据专业查询年级
    @RequestMapping("selectmid")
    @ResponseBody
    public LayuiResult<Map> selGradeDB(Integer mid)
        List<GradeDB> grade = studentService.selGradeDB(mid);
        LayuiResult result = new LayuiResult();
        result.setData(grade);
        return result;
    

    //  根据年级查询班级
    @RequestMapping("selectgid")
    @ResponseBody
    public LayuiResult<Map> selClassinfoDB(Integer gid)
        List<ClassinfoDB> classinfo = studentService.selClassinfoDB(gid);
        LayuiResult result = new LayuiResult();
        result.setData(classinfo);
        return result;
    


    //  根据id查询一条学生信息以此进行修改
    @RequestMapping("/selStudentId")
    public String selStudentId(Integer id, Model model)
        //  查询学生信息
        List<StudentDB> stu = studentService.selStudentId(id);
        //  查询班级
        List<ClassinfoDB> cls = studentService.selClass();
        //  查询政治面貌表
        List<PoliticsTypeDB> stupol = studentService.selPolitics();
        model.addAttribute("stu",stu);
        model.addAttribute("cls",cls);
        model.addAttribute("stupol",stupol);
        return "view/student/updStudent";
    

    //  根据id查询显示学生详细信息
    @RequestMapping("/selectMessage")
    public String selectMessage(Integer id, Model model)
        //  查询学生信息
        List<StudentDB> stu = studentService.selStudentId(id);
        //  查询班级
        List<ClassinfoDB> cls = studentService.selClass();
        //  查询政治面貌表
        List<PoliticsTypeDB> stupol = studentService.selPolitics();
        model.addAttribute("stu",stu);
        model.addAttribute("cls",cls);
        model.addAttribute("stupol",stupol);
        return "view/student/selStuExam";
    

    //  修改用户信息
    @RequestMapping("/updateStudent")
    @ResponseBody
    public LayuiResult<StudentDB> updateStudent(StudentDB studentDB, String birthday) throws Exception
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date=format.parse(birthday);
        studentDB.setSbirthday(date);
        studentService.updateStudent(studentDB);
        LayuiResult result= new LayuiResult();
        //删除提示
        result.setMsg("修改成功!");
        return result;
    

老师管理控制层:

@Controller
public class TeacherController 
    @Autowired
    private TeacherService lxxTeacherService;
    @Autowired
    private StudentService lxxStudentService;
    @Autowired
    private DeleteService deleteService;

    // 跳转教师查询页面
    @RequestMapping("/selectTeacher")
    public String selectTeacher()
        return "view/teacher/selTeacher";
    


    //  查询教师信息
    @RequestMapping("selTeacher")
    @ResponseBody
    public LayuiResult<Map> selTeacher(TeacherDB teacherDB, pageCount pageCount)
        LayuiResult<Map> result = new LayuiResult<>();
        //  查询所有教师信息/模糊查询教师信息
        List<Map> list = lxxTeacherService.selTeacher(teacherDB,pageCount);
        //  查询符合条件的教师数量
        int count = lxxTeacherService.selTeacherCount(teacherDB);
        result.setData(list);
        result.setCount(count);
        return result;
    

    //  根据教师编号查询教师信息
    @RequestMapping("/selTeacherId")
    public String selTeacherId(Integer id, Model model)
        List<TeacherDB> tea = lxxTeacherService.selTeacherId(id);
        //  查询政治面貌
        List<PoliticsTypeDB> selpol = lxxStudentService.selPolitics();
        model.addAttribute("tea",tea);
        model.addAttribute("selpol",selpol);
        return "view/teacher/updTeacher";
    

    //  根据教师编号查询教师详细信息
    @RequestMapping("/selectTeaMessage")
    public String selectTeaMessage(Integer id, Model model)
        List<TeacherDB> tea = lxxTeacherService.selTeacherId(id);
        //  查询政治面貌
        List<PoliticsTypeDB> selpol = lxxStudentService.selPolitics();
        model.addAttribute("tea",tea);
        model.addAttribute("selpol",selpol);
        return "view/teacher/selTchMessage";
    

    //  修改教师信息
    @RequestMapping("/updateTeacher")
    @ResponseBody
    public LayuiResult<TeacherDB> updTeacher(TeacherDB teacherDB, String birthday) throws Exception
        LayuiResult result= new LayuiResult();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date=format.parse(birthday);
        teacherDB.setTbirthday(date);
        Integer state = teacherDB.getTchstate();
        Integer tid = teacherDB.getTid();
        if(state == 1)
            //  修改教师为离职状态并逻辑删除
            Integer deleteTeacher = deleteService.deleteTeacher(teacherDB);
            //  删除教师授课信息
            Integer deleteTchCourse = deleteService.deleteTchCourse(tid);
            //  删除教师班级信息
            Integer deleteTchClass = deleteService.deleteTchClass(tid);
            //  删除教师成绩信息
            Integer deleteTchExam = deleteService.deleteTchExam(tid);
            //  删除教评记录信息
            Integer deleteTeaRecord = deleteService.deleteTeaRecord(tid);
            //  改用户登录状态改为(1)锁定状态
            Integer deleteUser = deleteService.deleteUser(teacherDB.getTchid());
            //删除提示
            result.setMsg("修改成功!");
            return result;
        else
            int a =lxxTeacherService.updTeacher(teacherDB);
            //删除提示
            result.setMsg("修改成功!");
            return result;
        
    


源码获取:博客首页 "资源" 里下载!

以上是关于Java项目:学生选课管理系统(java+SpringBoot+Mybatis-plus+Thymeleaf+mysql)的主要内容,如果未能解决你的问题,请参考以下文章

Java期末大作业基础项目--在线学生选课系统(建议收藏)

Java期末大作业基础项目--在线学生选课系统(建议收藏)

java学生选课系统

毕业设计So Easy:基于Java Web学生选课系统

毕业设计So Easy:基于Java Web学生选课系统

JAVA | 学生选课系统