Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)

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

Springboot框架+myBaits-Plus+MySQL实现的角色权限后台管理脚手架系统实战项目,实现的是所有系统最基础的后台管理功能,有了这个脚手架,以后开发别的项目就在这上面快速增加功能即可。本系统主要实现的功能有:菜单管理、角色管理、用户管理、登录、登出,不同的角色分配相应的权限,用户分配不同的角色登录后显示相应被分配的功能。

本系统采用前后端分离的思想设计,后端采用springboot微服务架构,主要包含一个网关服务和一个权限管理服务,开发其他功能可以再创建其他的微服务,前端采用vue+element-UI实现。

1.本系统开发所需的基础环境及版本:

软件

版本

jdk

1.8

MySQL

5.7

maven

3.6.1

nacos

1.1.4

Redis

5.0.10

Node

14.17.3

Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第1张图片

Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第2张图片

 Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第3张图片

 Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第4张图片

 Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第5张图片

 Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第6张图片

 Java项目:角色权限后台脚手架系统(java+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)_第7张图片

用户管理控制层:

@Controller
@RequestMapping("/user")
public class UserController extends BaseController{

    private String prefix = "system/user/";

    @Autowired
    IUserService iUserService;
    @Autowired
    IRoleService iRoleService;
    @Autowired
    IDeptService iDeptService;
    @Autowired
    IPositionService iPositionService;

    @Autowired
    private SysPasswordService passwordService;



    /**
     *
     * @描述 跳转到用户页面
     *
     * @date 2018/9/16 10:54
     */
    @RequestMapping("/tolist")
    @RequiresPermissions("user:list")
    public String toUserList()
    {
        return prefix + "user";
    }


    /**
     * @描述 用户数据
     * @date 2018/9/15 12:30
     */
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo list(User user)
    {
        startPage();
        List users = iUserService.selectByUser(user);

        return getDataTable(users);
    }


    /**
     * 编辑用户 system/user/edit/20180914-1
     */
    @RequiresPermissions("user:update")
    @RequestMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") String userId, Model model)
    {
        // 个人信息
        User user = iUserService.selectByPrimaryKey(userId);
        Map role_post_dept = getRole_Post_Dept();
        model.addAttribute("depts", role_post_dept.get("dept"));
        model.addAttribute("roles", role_post_dept.get("role"));
        model.addAttribute("positions", role_post_dept.get("position"));
        model.addAttribute("user", user);
        return prefix + "edit";
    }

    /**
     *
     * @描述 保存用户
     *
     * @date 2018/9/15 18:53
     */
    @PostMapping("/editSave")
    @RequiresPermissions("user:update")
    @Operlog(modal = "用户管理", descr = "修改用户信息")
    @ResponseBody
    public AjaxResult save(User user)
    {
        if (StringUtils.isNotNull(user.getUid()) && User.isBoss(user.getUid()))
        {
            return error("不允许修改管理员用户");
        }
        if(user.getPwd()!=null){
            user.setSalt(ShiroUtils.randomSalt());
            SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);
            user.setPwd(md5.toHex());
        }
        return result(iUserService.updateByPrimaryKeySelective(user));
    }


    /**
     * @描述 添加用户页面
     * @date 2018/9/15 18:46
     */
    @RequestMapping("/toAdd")
    @RequiresPermissions("user:add")
    public String toaddUser(Model model)
    {
        Map role_post_dept = getRole_Post_Dept();
        model.addAttribute("depts", role_post_dept.get("dept"));
        model.addAttribute("roles", role_post_dept.get("role"));
        model.addAttribute("positions", role_post_dept.get("position"));
        return prefix + "add";
    }

    /**
     *
     * @描述 添加用户
     *
     * @date 2018/9/15 20:40
     */

    @RequestMapping("/addSave")
    @RequiresPermissions("user:add")
    @Operlog(modal = "用户管理", descr = "添加用户")
    @ResponseBody
    public AjaxResult addUser(User user)
    {
        user.setSalt(ShiroUtils.randomSalt());
        SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);
        user.setPwd(md5.toHex());
        user.setAvatar(CsEnum.avatar.USER_AVATAR.getValue());
        user.setCreateTime(new Date());
        return result(iUserService.insertSelective(user));
    }

    /**
     *
     * @描述 批量删除
     *
     * @date 2018/9/16 9:31
     */
    @RequestMapping("/del")
    @RequiresPermissions("user:del")
    @Operlog(modal = "用户模块", descr = "删除用户")
    @ResponseBody
    public AjaxResult delByUserIds(String[] ids)
    {
        try
        {
            int i = iUserService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }

    /**
     *
     * @描述 编辑密码修改页面
     *
     * @date 2018/9/16 10:25
     */
    @RequestMapping("/resetPwd/{userId}")
    @RequiresPermissions("user:update")
    public String editPwd(@PathVariable("userId") String id, Model model)
    {
        model.addAttribute("uid", id);
        return prefix + "resetPwd";
    }


    /**
     *
     * @描述 密码修改
     *
     * @date 2018/9/16 10:42
     */

    @RequestMapping("/resetPwd")
    @RequiresPermissions("user:update")
    @Operlog(modal = "用户模块", descr = "修改密码")
    @ResponseBody
    public AjaxResult resetPwd(User user)
    {
        return result(iUserService.resrtPwd(user));
    }

    /**
     * 校验手机号码
     */
    @PostMapping("/checkPhoneUnique")
    @ResponseBody
    public String checkPhoneUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkPhoneUnique(user);
        }
        return uniqueFlag;
    }

    /**
     * 校验email邮箱
     */
    @PostMapping("/checkEmailUnique")
    @ResponseBody
    public String checkEmailUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkEmailUnique(user);
        }
        return uniqueFlag;
    }


    /**
     *
     * @描述: 校验登录名唯一性
     *
     * @params:
     * @return:
     * @date: 2018/10/2 17:06
     */
    @PostMapping("/checkLoginNameUnique")
    @ResponseBody
    public String checkLoginNameUnique(User user)
    {
        String uniqueFlag = "0";
        if (user != null)
        {
            uniqueFlag = iUserService.checkLoginNameUnique(user);
        }
        return uniqueFlag;
    }


    public Map getRole_Post_Dept()
    {
        Map map = new HashMap<>();
//        角色
        List roles = iRoleService.selectRoleList(new Role());
//        部门信息
        List depts = iDeptService.selectDeptList(new Dept());
//        岗位
        List positions = iPositionService.selectPositionList(new Position());
        map.put("role", roles);
        map.put("dept", depts);
        map.put("position", positions);

        return map;
    }


    /**
     * 用户个人信息查看页面
     */
    @RequestMapping("/myMsg")
    public String ToMyMsg(Model model, HttpServletRequest request)
    {
        User user = iUserService.selectByPrimaryKey(getUserId());
        model.addAttribute("user", user);
        model.addAttribute("loginIp", HttpHeaderUtil.getIpAddr(request));
        return prefix + "profile/msg";
    }


    /**
     * 密码修改页面
     */
    @RequestMapping("/resetMyPwd")
    public String toResetPwd(Model model)
    {
        User user = iUserService.selectByPrimaryKey(getUserId());
        model.addAttribute("user", user);
        return prefix + "profile/resetPwd";
    }

    /**
     * 密码修改保存
     */
    @RequestMapping("/updateMyPwdSave")
    @ResponseBody
    @RequiresPermissions("user:update")
    @Operlog(modal = "个人信息", descr = "修改密码")
    public AjaxResult updateMyPwdSave(String password)
    {
        User user = new User();
        user.setSalt(ShiroUtils.randomSalt());
        SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);
        user.setPwd(md5.toHex());
        user.setUid(getUserId());
        int i = iUserService.updateByPrimaryKeySelective(user);
        if (i > 0)
        {
            //更新shiro中的信息
            ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
            return success();
        }
        return error();
    }

    /**
     * 编辑用户头像修改
     */
    @RequestMapping("/updateAvatar")
    public String toupdateAvatar(Model model)
    {
        model.addAttribute("user", getUser());
        return prefix + "profile/avatar";
    }

    /**
     * 修改保存用户头像
     */
    @RequestMapping("/updateAvatarSave")
    @RequiresPermissions("user:update")
    @Operlog(modal = "个人信息", descr = "修改头像")
    @ResponseBody
    public AjaxResult toupdateAvatar(MultipartFile file)
    {
        try
        {
            String imgPath = UploadFile.uploadUserImg(file);
            if (StringUtils.isEmpty(imgPath))
            {
                return error("图片上传失败,稍后再试!");
            }

            User user = new User();
            user.setUid(getUserId());
            user.setAvatar(imgPath);
            int i = iUserService.updateByPrimaryKeySelective(user);
            if (i > 0)
            {
                ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
            }
            return result(i);
        }
        catch (IOException e)
        {
            return error();
        }
        catch (FileSizeException e)
        {
            //文件过大
            return error(e.getMsg());
        }
        catch (FileNameLengthException e)
        {
            //文件名字超长
            return error(e.getMsg());
        }
    }


    /**
     * 校验密码和原来密码是否相同
     */
    @RequestMapping("/checkPassword")
    @ResponseBody
    public boolean checkPassword(String password)
    {
        //加密后与数据库密码比较
        User user = getUser();
        SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);
        String oldPassword = md5.toHex();
        String pwd = getPwd();
        if (pwd.equals(oldPassword))
        {
            return true;
        }
        return false;
    }


}

角色管理控制层:

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController{
    private String prefix = "system/role/";


    @Autowired
    IUserService iUserService;

    @Autowired
    IRoleService iRoleService;

    @Autowired
    IPermissionService iPermissionService;

    /**
     *
     * @描述 页面跳转
     *
     * @date 2018/9/16 10:59
     */
    @RequestMapping("/tolist")
    @RequiresPermissions("role:list")
    public String tolist()
    {
        return prefix + "role";
    }


    /**
     *
     * @描述 ajax请求所有
     *
     * @date 2018/9/16 10:48
     */
    @RequestMapping("/ajaxlist")
    @ResponseBody
    public List list(Role role)
    {
        List roles = iRoleService.selectRoleList(role);
        return roles;
    }

    /**
     *
     * @描述 列表
     *
     * @date 2018/9/16 10:52
     */
    @RequestMapping("/tableList")
    @ResponseBody
    public TableDataInfo listPag(Role role)
    {
        //开启分页
        startPage();
        List roles = iRoleService.selectRoleList(role);
        return getDataTable(roles);
    }


    /**
     *
     * @描述 新增页面
     *
     * @date 2018/9/16 11:37
     */
    @RequestMapping("/toAdd")
    @RequiresPermissions("role:add")
    public String toAdd(Model model)
    {
        return prefix + "add";
    }


    /**
     *
     * @描述 批量删除
     *
     * @date 2018/9/16 11:53
     */
    @RequestMapping("/del")
    @RequiresPermissions("role:del")
    @Operlog(modal = "角色管理",descr = "删除角色")
    @ResponseBody
    public AjaxResult del(Integer[] ids)
    {
        try
        {
            iRoleService.deleteByPrimaryKeys(ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return success();
    }


    /**
     *
     * @描述 添加保存
     *
     * @date 2018/9/16 11:54
     */

    @RequestMapping("/addSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "添加角色")
    @ResponseBody
    public AjaxResult addRole(Role role, Integer[] ids)
    {
        role.setCreateTime(new Date());
        int insert = 0;
        try
        {
            if (StringUtils.isEmpty(ids))
            {
                ids = new Integer[0];
            }
            insert = iRoleService.insert(role, ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        //清空缓存
        ShiroUtils.clearCachedAuthorizationInfo();
        return  result(insert);
    }


    /**
     *
     * @描述: 根据ID 获取u他的所有权限 做回显
     *
     * @params: roleId 角色Id
     * @return:
     * @date: 2018/9/27 14:04
     */
    @RequestMapping("/selectById/{roleId}")
    @ResponseBody
    public Role selectById(@PathVariable("roleId") Integer roleId)
    {
        Role role = iRoleService.selectByPrimaryKey(roleId);
        return role;
    }


    /**
     *
     * @描述 编辑修改页面
     *
     * @date 2018/9/16 14:06
     */
    @RequestMapping("/edit/{id}")
    @RequiresPermissions("role:update")
    public String edit(@PathVariable("id") Integer id, Model model)
    {
        Role role = iRoleService.selectByPrimaryKey(id);
        model.addAttribute("Role", role);
        return prefix + "edit";
    }

    /**
     *
     * @描述 编辑修改权限页面
     *
     * @date 2018/9/16 14:06
     */
    @RequestMapping("/editPower/{id}")
    @RequiresPermissions("role:update")
    public String editPower(@PathVariable("id") Integer id, Model model)
    {
        Role role = iRoleService.selectByPrimaryKey(id);
        model.addAttribute("Role", role);
        return prefix + "editPower";
    }


    /**
     *
     * @描述 修改角色信息保存
     *
     * @date 2018/9/16 16:12
     */
    @RequestMapping("/editSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "修改角色信息")
    @ResponseBody
    public AjaxResult save(Role role)
    {
        int i = 0;
        try
        {
            i = iRoleService.updateByPrimaryKeySelective(role);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        return result(i);
    }


    /**
     *
     * @描述 修改角色权限信息保存
     *
     * @date 2018/9/16 16:12
     */
    @RequestMapping("/editPowerSave")
    @RequiresPermissions("role:update")
    @Operlog(modal = "角色管理",descr = "修改角色权限")
    @ResponseBody
    public AjaxResult editPowerSave(Role role, Integer[] ids)
    {
        int i = 0;
        try
        {
            if (StringUtils.isEmpty(ids))
            {
                ids = new Integer[0];
            }
            i = iRoleService.updateByPrimaryKeyPowerSelective(role, ids);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
        //清空缓存
        ShiroUtils.clearCachedAuthorizationInfo();
        //如果用户正在修改的角色id 是当前用户的角色id 则刷新 subject的User信息
        if (role.getRoleId().equals(getRoleId()))
        {
            ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));
        }
        return result(i);
    }


    /**
     * 校验名称唯一
     */
    @PostMapping("/checkRoleNameUnique")
    @ResponseBody
    public String checkDeptNameUnique(Role role)
    {
        String uniqueFlag = "0";
        if (role != null)
        {
            uniqueFlag = iRoleService.checkRoleNameUnique(role);
        }
        return uniqueFlag;
    }
}

登录管理控制层:

@org.springframework.stereotype.Controller
@RequestMapping("/oa")
public class LoginController extends BaseController{
    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    private String prefix = "system/user/";

    @Autowired
    LoginService loginService;


    @Autowired
    IUserService userService;



    /**
     *
     * @描述: 执行登录操作
     *
     * @params: user:用户登录信息;
     *          validateCode:验证码
     * @return:
     * @date: 2018/9/29 21:20
     */
    @RequestMapping("/login")
    @Operlog(descr = "用户登录", modal = "登录模块")
    @ResponseBody
    public AjaxResult Logining(User user, String validateCode, Boolean rememberMe, HttpServletRequest request)
    {
        HttpSession session = ServletUtils.getSession();

        UsernamePasswordToken token = new UsernamePasswordToken(user.getName(), user.getPwd());
        token.setRememberMe(rememberMe);
        Subject subject = SecurityUtils.getSubject();

        //验证用户名和密码 验证码的问题
        try
        {
            loginService.checkLogin(user.getName(), user.getPwd(), validateCode);
        }
        catch (Exception e)
        {
            session.setAttribute(Constants.LOGIN_ERROR, e.getMessage());
            return error(e.getMessage());
        }
        try
        {
            if (!subject.isAuthenticated())
            {
                subject.login(token);
            }
        }
        catch (IncorrectCredentialsException e)
        {
            session.setAttribute(Constants.LOGIN_ERROR,"密码错误");
            return error("密码错误!");
        }
        catch (UnknownAccountException e)
        {
            session.setAttribute(Constants.LOGIN_ERROR,e.getMessage());
            return error(e.getMessage());
        }
        catch (LockedAccountException e)
        {
            session.setAttribute("login",e.getMessage());
            return error(e.getMessage());
        }
        catch (AuthenticationException e)
        {
//            String msg = "用户名或密码错误!";
//            if (!StringUtils.isEmpty(e.getMessage()))
//            {
//                msg = e.getMessage();
//            }
            session.setAttribute(Constants.LOGIN_ERROR,e.getMessage());
            return error("系统异常!");
        }

        return success();
    }


    /**
 s sl
       *
     * @描述: 登录页面
     *
     * @params:
     * @return:
     * @date: 2018/9/29 21:20
     */
    @RequestMapping("/toLogin")
    public String toLogin()
    {
        return "login";
    }


}

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

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