基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)

发布时间:2024-05-12 08:01

基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)

一、项目简述
功能:包括学生管理,班级管理,宿舍管理,人员信息维 护。维修登记,卫生管理,访客管理等等。

二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + ldea2019 (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven

\"基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)_第1张图片\"
\"基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)_第2张图片\"
\"基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)_第3张图片\"
\"基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)_第4张图片\"
\"基于javaweb+jsp的宿舍管理系统(java+jsp+SSM+Spring+mysql)_第5张图片\"

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

    public String doAdd(Role role){
        //角色添加
        return \"ok\";
    }
    //添加角色
    @RequestMapping(\"/role/addRole\")
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public AjaxResult addRole(Role role){
        System.out.println(\"保存角色....\"+role);
        try {
            roleService.saveRole(role);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(\"操作失败\");
        }
    }
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @RequestMapping(\"/role/index\")
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public AjaxResult addRole(Role role){
        System.out.println(\"保存角色....\"+role);
        try {
            roleService.saveRole(role);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(\"操作失败\");
        }
    }
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @RequestMapping(\"/role/index\")
    public String index(Model model){
        List<Permission> permisisons = permissionService.findAllPermisisons();
        model.addAttribute(\"permissions\",permisisons);
        //返回角色
        return \"views/role/role_list\";
    }
    @RequestMapping(\"/role/listpage\")
    @ResponseBody
    public PageList listpage(RoleQuery roleQuery){
        System.out.println(\"传递参数:\"+roleQuery);
        if(user.getType() == 2) {
            //保存老师组
            userService.saveRel(is, userInfo, tGroup);
        }
        if(user.getType() == 3) {
            //保存学生组
            userService.saveRel(is, userInfo, stuGroup);
        }
        Long userId = user.getId();
        return userId;
    }
    /**
     * 修改密码页面
     * @return
     */
    @RequestMapping(value=\"/update_pwd\",method=RequestMethod.GET)
    public String updatePwd(){
        return \"views/user/update_pwd\";
    }
    /**
     * 修改密码页面
     * @return
     */
    @RequestMapping(value=\"/update_pwd\",method=RequestMethod.GET)
    public String updatePwd(){
        return \"views/user/update_pwd\";
    }
    /**
        if(user.getType() == 2) {
            //保存老师组
            userService.saveRel(is, userInfo, tGroup);
        }
        if(user.getType() == 3) {
            //保存学生组
            userService.saveRel(is, userInfo, stuGroup);
        }
        Long userId = user.getId();
        return userId;
    }
    /**
     * 修改密码页面
     * @return
     */
    @RequestMapping(value=\"/update_pwd\",method=RequestMethod.GET)
    public String updatePwd(){
        return \"views/user/update_pwd\";
    }
    /**
     * 修改密码操作
     * @param oldPwd
     * @param newPwd
     * @return
            return ret;
        }
        if(StringUtils.isEmpty(user.getEmail())){
            ret.put(\"msg\",\"请填写邮箱\");
            return ret;
        }
        if(StringUtils.isEmpty(user.getTel())){
            ret.put(\"msg\",\"请填写手机号\");
            return ret;
        }
        response.setHeader(\"Cache-Control\",\"no-store\");
        response.setHeader(\"Pragrma\",\"no-cache\");
        response.setDateHeader(\"Expires\",0);
      return  Message.success();
    }
}
文件上传接口:
@Controller
@Api(tags = \"文件上传接口\")
public class FileUpload {
    @Autowired
    private IUserService userService;
    @Value(\"${lyy.upload.path}\")
    private String uploadPath;
        }
        ret.put(\"code\",0);
        ret.put(\"msg\",\"添加用户成功\");
        return ret;
    }
    /**
     * 修改用户信息操作
     * @param user
     * @return
     */
    @PostMapping(\"/editSaveUser\")
    public Message editSaveUser(User user){
        if(StringUtils.isEmpty(user.getUsername())){
          return Message.error(\"请填写用户名\");
        }
        if(StringUtils.isEmpty(user.getEmail())){
            return Message.error(\"请填写邮箱\");
        }
        if(StringUtils.isEmpty(user.getTel())){
            return Message.error(\"请填写手机号\");
        }
        try {
            userService.editSaveUser(user);
            return Message.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Message.error(\"修改用户信息失败\");
        }
    }
    //添加用户
    @GetMapping(\"/deleteUser\")
    @ApiOperation(\"删除用户接口\")
    @ApiImplicitParams({
            @ApiImplicitParam(name = \"id\", value = \"如:88\",required = true)
            @ApiImplicitParam(name = \"paramMap\", value = \"如:{userId:1,[1,2,3,4]]}\")
    })
    @ResponseBody
    public AjaxResult addUserRole(@RequestBody Map paramMap){
        AjaxResult ajaxResult = new AjaxResult();
        String userId = (String)paramMap.get(\"userId\");
        List roleIds = (List) paramMap.get(\"roleIds\");
        try {
            //添加用户对应的角色
            roleService.addUserRole(userId,roleIds);
            return ajaxResult;
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(\"保存角色失败\");
        }
    }
    //添加用户
    @RequestMapping(\"/regSaveUser\")
    @ResponseBody
    public Long addTeacher(User user){
        System.out.println(\"保存用户....\"+user);
     * @param oldPwd
     * @param newPwd
     * @return
     */
    @ResponseBody
    @PostMapping(\"/update_pwd\")
    public Message updatePassword(@RequestParam(name=\"oldPwd\",required=true)String oldPwd,
                                  @RequestParam(name=\"newPwd\",required=true)String newPwd){
        String username = CommonUtils.getLoginUser().getUsername();
        User userByUserName = userService.findUserByUserName(username);
        if(userByUserName!=null){
            String password = userByUserName.getPassword();
            BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
            boolean matches = bCryptPasswordEncoder.matches(oldPwd, password);
            if(!matches){
        List roleIds = (List) paramMap.get(\"roleIds\");
        try {
            //添加用户对应的角色
            roleService.addUserRole(userId,roleIds);
            return ajaxResult;
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(\"保存角色失败\");
        }
    }
    //添加用户
    @RequestMapping(\"/regSaveUser\")
    @ResponseBody
    public Long addTeacher(User user){
        System.out.println(\"保存用户....\"+user);
        userService.addUser(user);
        //保存工作流程操作
        IdentityService is = engine.getIdentityService();
        // 添加用户组
        org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername());
    @RequestMapping(\"/role/index\")
    public String index(Model model){
        List<Permission> permisisons = permissionService.findAllPermisisons();
        model.addAttribute(\"permissions\",permisisons);
        //返回角色
        return \"views/role/role_list\";
    }
    @RequestMapping(\"/role/listpage\")
    @ResponseBody
    public PageList listpage(RoleQuery roleQuery){
        System.out.println(\"传递参数:\"+roleQuery);
        return  roleService.listpage(roleQuery);
    }
    //修改用户editSaveUser
    @RequestMapping(\"/role/editSaveRole\")
    @ResponseBody
    public AjaxResult editSaveRole(Role role){
        System.out.println(\"修改角色....\"+role);
    //添加用户的角色
    @PostMapping(\"/addUserRole\")
    @ApiOperation(\"添加用户角色接口\")
    @ApiImplicitParams({
            @ApiImplicitParam(name = \"paramMap\", value = \"如:{userId:1,[1,2,3,4]]}\")
    })
    @ResponseBody
    public AjaxResult addUserRole(@RequestBody Map paramMap){
        AjaxResult ajaxResult = new AjaxResult();
        String userId = (String)paramMap.get(\"userId\");
        List roleIds = (List) paramMap.get(\"roleIds\");
        try {
            //添加用户对应的角色
            roleService.addUserRole(userId,roleIds);
            return ajaxResult;
        }catch (Exception e){
     public AjaxResult upload(HttpServletRequest req, Integer id, @RequestParam(\"file\") MultipartFile file){
        try {
            if(file.isEmpty()){
                return new AjaxResult(\"文件为空\");
            }
            String fileName = file.getOriginalFilename();
            String suffixName = fileName.substring(fileName.lastIndexOf(\".\"));
            String uuidString = UUID.randomUUID().toString();
            String newFileName= uuidString + suffixName;
            File path = new File(uploadPath);
            if (!path.exists()) path.mkdirs();
            File savefile = new File(path,newFileName);
            if (!savefile.getParentFile().exists()) savefile.getParentFile().mkdirs();
            file.transferTo(savefile);
            //更新用户表的头像
            User user = new User();
        return \"ok\";
    }
    //添加角色
    @RequestMapping(\"/role/addRole\")
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public AjaxResult addRole(Role role){
        System.out.println(\"保存角色....\"+role);
        try {
            roleService.saveRole(role);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(\"操作失败\");
        }
    }
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @RequestMapping(\"/role/index\")
    public String index(Model model){
        List<Permission> permisisons = permissionService.findAllPermisisons();
    @ApiOperation(\"修改用户接口\")
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public Message editSaveUser(User user){
        if(StringUtils.isEmpty(user.getUsername())){
          return Message.error(\"请填写用户名\");
        }
        if(StringUtils.isEmpty(user.getEmail())){
            return Message.error(\"请填写邮箱\");
        }
        if(StringUtils.isEmpty(user.getTel())){
            return Message.error(\"请填写手机号\");
    }
}
用户管理控制器:
/**
 * 用户管理控制器
 */
@RequestMapping(\"/user/\")
@Controller
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;
    @Resource
        // 获得的系统的根目录
        File fileParent = new File(File.separator);
        // 获得/usr/CBeann目录
        File file = null ;
        String os = System.getProperty(\"os.name\");
        ServletOutputStream out = response.getOutputStream();
        try {
            if (os.toLowerCase().startsWith(\"win\")) {  //如果是Windows系统
                file = new File(uploadPath +\"\\\\\"+ image_name);
            } else {  //linux 和mac
                file = new File(fileParent, uploadPath.substring(1) +\"/\"+ image_name);
            }
            IOUtils.copy(new FileInputStream(file),out);
            out.flush();
        } finally {
     */
    @PostMapping(\"/editSaveUser\")
    @ApiOperation(\"修改用户接口\")
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public Message editSaveUser(User user){
        if(StringUtils.isEmpty(user.getUsername())){
          return Message.error(\"请填写用户名\");
        }
        if(StringUtils.isEmpty(user.getEmail())){
    }
    //添加用户的角色
    @PostMapping(\"/addUserRole\")
    @ApiOperation(\"添加用户角色接口\")
    @ApiImplicitParams({
            @ApiImplicitParam(name = \"paramMap\", value = \"如:{userId:1,[1,2,3,4]]}\")
    })
    @ResponseBody
    public AjaxResult addUserRole(@RequestBody Map paramMap){
        AjaxResult ajaxResult = new AjaxResult();
        String userId = (String)paramMap.get(\"userId\");
        List roleIds = (List) paramMap.get(\"roleIds\");
        try {
        response.setDateHeader(\"Expires\",0);
      return  Message.success();
    }
}
文件上传接口:
@Controller
@Api(tags = \"文件上传接口\")
public class FileUpload {
    @Autowired
    private IUserService userService;
    @Value(\"${lyy.upload.path}\")
    private String uploadPath;
    @RequestMapping(value=\"/file/uploadFile\", method= RequestMethod.POST)
    @ResponseBody
     public AjaxResult upload(HttpServletRequest req, Integer id, @RequestParam(\"file\") MultipartFile file){
    @ResponseBody
    public Long addTeacher(User user){
        System.out.println(\"保存用户....\"+user);
        userService.addUser(user);
        //保存工作流程操作
        IdentityService is = engine.getIdentityService();
        // 添加用户组
        org.activiti.engine.identity.User userInfo = userService.saveUser(is, user.getUsername());
        // 添加用户对应的组关系
        Group stuGroup = new GroupEntityImpl();
        stuGroup.setId(\"stuGroup\");
        Group tGroup = new GroupEntityImpl();
        tGroup.setId(\"tGroup\");
        if(user.getType() == 2) {
            //保存老师组
            userService.saveRel(is, userInfo, tGroup);
        }
    @RequestMapping(\"/role/editSaveRole\")
    @ResponseBody
    public AjaxResult editSaveRole(Role role){
        System.out.println(\"修改角色....\"+role);
        try {
            roleService.editSaveRole(role);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxResult(\"修改失败\");
    }
    //添加角色
    @RequestMapping(\"/role/deleteRole\")
    @ResponseBody
    public AjaxResult deleteRole(Long id){
        System.out.println(\"删除角色....\"+id);
        AjaxResult ajaxResult = new AjaxResult();
            return Message.error(\"请填写手机号\");
        }
        try {
            userService.editSaveUser(user);
            return Message.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Message.error(\"修改用户信息失败\");
        }
    }
    //添加用户
    @GetMapping(\"/deleteUser\")
    @ApiOperation(\"删除用户接口\")
    @ApiImplicitParams({
            @ApiImplicitParam(name = \"id\", value = \"如:88\",required = true)
    })
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public AjaxResult deleteUser(@RequestParam(required = true) Long id){
        AjaxResult ajaxResult = new AjaxResult();
        }
        if(StringUtils.isEmpty(user.getTel())){
            return Message.error(\"请填写手机号\");
        }
        try {
            userService.editSaveUser(user);
            return Message.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Message.error(\"修改用户信息失败\");
        }
    }
    //添加用户
    @GetMapping(\"/deleteUser\")
    @ApiOperation(\"删除用户接口\")
    @ApiImplicitParams({
            @ApiImplicitParam(name = \"id\", value = \"如:88\",required = true)
    })
    @PreAuthorize(\"hasRole(\'管理员\')\")
    @ResponseBody
    public AjaxResult deleteUser(@RequestParam(required = true) Long id){
        AjaxResult ajaxResult = new AjaxResult();
            User user = new User();
            user.setId(Long.parseLong(id+\"\"));
            user.setHeadImg(newFileName);
            userService.updateUserHeadImg(user);
            return new AjaxResult();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @RequestMapping(value = \"/showimage/{image_name}\")
    public String showphoto(@PathVariable(\"image_name\") String image_name,HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        response.setDateHeader(\"Expires\", 0);
        response.setHeader(\"Cache-Control\", \"no-store, no-cache, must-revalidate\");
        response.addHeader(\"Cache-Control\", \"post-check=0, pre-check=0\");
        response.setHeader(\"Pragma\", \"no-cache\");
        response.setContentType(\"image/jpeg\");
        // 获得的系统的根目录
        File fileParent = new File(File.separator);

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号