Java项目:学生管理系统(java+Springboot+Maven+mybatis+Vue+Mysql)

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

一、项目简述


本系统功能包括:
学生管理,教师管理,课程管理,成绩管理,系统管理等等。


二、项目运行

环境配置:


Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。


项目技术:


Springboot + Maven + mybatis+ Vue 等等组成,B/S模式 + Maven管理等等。


学生管理控制层:

@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 list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                               @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                               ServletRequest request){
        Map map = WebUtils.getParametersStartingWith(request, "s_");
        PageData userPageData = new PageData<>();
        QueryWrapper 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 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 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 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 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 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 selTeacher(TeacherDB teacherDB, pageCount pageCount){
        LayuiResult result = new LayuiResult<>();
        //  查询所有教师信息/模糊查询教师信息
        List 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 tea = lxxTeacherService.selTeacherId(id);
        //  查询政治面貌
        List 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 tea = lxxTeacherService.selTeacherId(id);
        //  查询政治面貌
        List selpol = lxxStudentService.selPolitics();
        model.addAttribute("tea",tea);
        model.addAttribute("selpol",selpol);
        return "view/teacher/selTchMessage";
    }

    //  修改教师信息
    @RequestMapping("/updateTeacher")
    @ResponseBody
    public LayuiResult 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;
        }
    }

}

角色管理控制层:

@Controller
@RequestMapping("admin/system/role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @Autowired
    UserService userService;

    @Autowired
    MenuService menuService;

    @RequestMapping(value = "list")
    public String list(){
        return "admin/role/list";
    }

    @RequiresPermissions("sys:role:list")
    @PostMapping("list")
    @ResponseBody
    public PageData list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                               @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                               ServletRequest request){
        Map map = WebUtils.getParametersStartingWith(request, "s_");
        PageData rolePageData = new PageData<>();
        QueryWrapper roleWrapper = new QueryWrapper<>();
        roleWrapper.eq("del_flag",false);
        if(!map.isEmpty()){
            String keys = (String) map.get("key");
            if(StringUtils.isNotBlank(keys)) {
                roleWrapper.like("name", keys);
            }
        }
        IPage rolePage = roleService.page(new Page<>(page,limit),roleWrapper);
        rolePageData.setCount(rolePage.getTotal());
        rolePageData.setData(setUserToRole(rolePage.getRecords()));
        return rolePageData;
    }

    private List setUserToRole(List roles){
        roles.forEach(r -> {
            if(StringUtils.isNotBlank(r.getCreateId())){
                User u = userService.findUserById(r.getCreateId());
                if(StringUtils.isBlank(u.getNickName())){
                    u.setNickName(u.getLoginName());
                }
                r.setCreateUser(u);
            }
            if(StringUtils.isNotBlank(r.getUpdateId())){
                User u  = userService.findUserById(r.getUpdateId());
                if(StringUtils.isBlank(u.getNickName())){
                    u.setNickName(u.getLoginName());
                }
                r.setUpdateUser(u);
            }
        });

        return roles;
    }

    @RequestMapping("add")
    public String add(ModelMap modelMap){
        Map map =  new HashMap();
        map.put("parentId",null);
        map.put("isShow",false);
        List menuList = menuService.selectAllMenus(map);
        modelMap.put("menuList",menuList);
        return "admin/role/add";
    }

    @RequiresPermissions("sys:role:add")
    @PostMapping("add")
    @ResponseBody
    @SysLog("保存新增角色数据")
    public ResponseEntity add(@RequestBody Role role){
        if(StringUtils.isBlank(role.getName())){
            return ResponseEntity.failure("角色名称不能为空");
        }
        if(roleService.getRoleNameCount(role.getName())>0){
            return ResponseEntity.failure("角色名称已存在");
        }
        roleService.saveRole(role);
        return ResponseEntity.success("操作成功");
    }

    @RequestMapping("edit")
    public String edit(String id,ModelMap modelMap){
        Role role = roleService.getRoleById(id);
        String menuIds = null;
        if(role != null) {
            menuIds  = role.getMenuSet().stream().map(menu -> menu.getId()).collect(Collectors.joining(","));
        }
        Map map = new HashMap();
        map.put("parentId",null);
        map.put("isShow",Boolean.FALSE);
        List menuList = menuService.selectAllMenus(map);
        modelMap.put("role",role);
        modelMap.put("menuList",menuList);
        modelMap.put("menuIds",menuIds);
        return "admin/role/edit";
    }

    @RequiresPermissions("sys:role:edit")
    @PostMapping("edit")
    @ResponseBody
    @SysLog("保存编辑角色数据")
    public ResponseEntity edit(@RequestBody Role role){
        if(StringUtils.isBlank(role.getId())){
            return ResponseEntity.failure("角色ID不能为空");
        }
        if(StringUtils.isBlank(role.getName())){
            return ResponseEntity.failure("角色名称不能为空");
        }
        Role oldRole = roleService.getRoleById(role.getId());
        if(!oldRole.getName().equals(role.getName())){
            if(roleService.getRoleNameCount(role.getName())>0){
                return ResponseEntity.failure("角色名称已存在");
            }
        }
        roleService.updateRole(role);
        return ResponseEntity.success("操作成功");
    }

    @RequiresPermissions("sys:role:delete")
    @PostMapping("delete")
    @ResponseBody
    @SysLog("删除角色数据")
    public ResponseEntity delete(@RequestParam(value = "id",required = false)String id){
        if(StringUtils.isBlank(id)){
            return ResponseEntity.failure("角色ID不能为空");
        }
        Role role = roleService.getRoleById(id);
        roleService.deleteRole(role);
        return ResponseEntity.success("操作成功");
    }

    @RequiresPermissions("sys:role:delete")
    @PostMapping("deleteSome")
    @ResponseBody
    @SysLog("多选删除角色数据")
    public ResponseEntity deleteSome(@RequestBody List roles){
        if(roles == null || roles.size()==0){
            return ResponseEntity.failure("请选择需要删除的角色");
        }
        for (Role r : roles){
            roleService.deleteRole(r);
        }
        return ResponseEntity.success("操作成功");
    }
}

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

你可能感兴趣的:(Java毕业设计项目实战篇,java,mysql,maven,spring,boot,vue.js)