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

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

用户管理控制层:

@Controller
@RequestMapping("/user")
public class UserController extends BaseController{private String prefix = "system/user/";@AutowiredIUserService iUserService;@AutowiredIRoleService iRoleService;@AutowiredIDeptService iDeptService;@AutowiredIPositionService iPositionService;@Autowiredprivate 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")@ResponseBodypublic TableDataInfo list(User user){startPage();List<User> 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<String, Object> 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 = "修改用户信息")@ResponseBodypublic 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<String, Object> 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 = "添加用户")@ResponseBodypublic 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 = "删除用户")@ResponseBodypublic 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 = "修改密码")@ResponseBodypublic AjaxResult resetPwd(User user){return result(iUserService.resrtPwd(user));}/*** 校验手机号码*/@PostMapping("/checkPhoneUnique")@ResponseBodypublic String checkPhoneUnique(User user){String uniqueFlag = "0";if (user != null){uniqueFlag = iUserService.checkPhoneUnique(user);}return uniqueFlag;}/*** 校验email邮箱*/@PostMapping("/checkEmailUnique")@ResponseBodypublic 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")@ResponseBodypublic String checkLoginNameUnique(User user){String uniqueFlag = "0";if (user != null){uniqueFlag = iUserService.checkLoginNameUnique(user);}return uniqueFlag;}public Map<String, Object> getRole_Post_Dept(){Map<String, Object> map = new HashMap<>();
//        角色List<Role> roles = iRoleService.selectRoleList(new Role());
//        部门信息List<Dept> depts = iDeptService.selectDeptList(new Dept());
//        岗位List<Position> 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 = "修改头像")@ResponseBodypublic 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")@ResponseBodypublic 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/";@AutowiredIUserService iUserService;@AutowiredIRoleService iRoleService;@AutowiredIPermissionService 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")@ResponseBodypublic List<Role> list(Role role){List<Role> roles = iRoleService.selectRoleList(role);return roles;}/**** @描述 列表** @date 2018/9/16 10:52*/@RequestMapping("/tableList")@ResponseBodypublic TableDataInfo listPag(Role role){//开启分页startPage();List<Role> 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 = "删除角色")@ResponseBodypublic 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 = "添加角色")@ResponseBodypublic 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}")@ResponseBodypublic 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 = "修改角色信息")@ResponseBodypublic 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 = "修改角色权限")@ResponseBodypublic 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")@ResponseBodypublic 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/";@AutowiredLoginService loginService;@AutowiredIUserService userService;/**** @描述: 执行登录操作** @params: user:用户登录信息;*          validateCode:验证码* @return:* @date: 2018/9/29 21:20*/@RequestMapping("/login")@Operlog(descr = "用户登录", modal = "登录模块")@ResponseBodypublic 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+Springboot+Maven+myBaits-Plus+Vue+Element-UI+Mysql)相关推荐

  1. Java项目:实现个人博客系统(java+springboot+mybatis+redis+vue+elementui+Mysql)

    源码获取:博客首页 "资源" 里下载! springboot+mybatis+前端vue,使用前后端分离架构实现的个人博客系统,共7个模块,首页,写博客,博客详情页,评论管理,文章 ...

  2. Java项目:(小程序)幼儿园报名系统(java+weixin-java-mp+spring+spring mvc+mybatis+layui+微信小程序)

    源码获取:博客首页 "资源" 里下载! 一.项目简述 本系统功能包括: 1 .登记管理 2 .基础管理 3 .公示公告 4 .首页展示 二.项目运行 环境配置: jdk8+tomc ...

  3. Java项目:医药进销存系统(java+SSM+JSP+Layui+jQuery+Maven+mysql)

    源码获取:博客首页 "资源" 里下载! 功能介绍 医药进销存系统,主要功能包括: 公告管理:发布公告.公告列表: 生产管理:订单列表.增加生产.订单日志: 分店采购:分店审核.采购 ...

  4. Java项目:课程自动排课系统(java+SpringBoot+html+layui+thymeleaf+redis+mysql)

    源码获取:博客首页 "资源" 里下载! 项目介绍 课程自动排课系统,该系统分两种角色:管理员与普通用户: 主要功能包括: 首页:查看分课.查看课表.查看空教室: 班级设置:添加班级 ...

  5. Java项目:校园外卖点餐系统(java+SSM+JSP+maven+mysql)

    源码获取:博客首页 "资源" 里下载! 一.项目简述 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclisp ...

  6. Java项目:宠物医院预约挂号系统(java+JSP+Spring+SpringBoot+MyBatis+html+layui+maven+Mysql)

    源码获取:博客首页 "资源" 里下载! 一.项目简述 功能包括: 用户分为宠物,医生,管理员,宠物主人可进行注册选择医生挂号,选择日期,选择号源,医生可进行宠物接诊,管理员可对宠物 ...

  7. Java项目:小蜜蜂扩音器网上商城系统(java+JSP+Servlet+JDBC+Ajax+mysql)

    源码获取:博客首页 "资源" 里下载! 一.项目简述 用户功能模块: 用户注册: 用户登录:商品模块:订单模块:后台管理系统功能:管理员模块: 商品模块:订单管理模块 : 二.项目 ...

  8. Java项目:嘟嘟二手书商城系统(java+JSP+Springboot+maven+mysql+ThymeLeaf+FTP)

    源码获取:博客首页 "资源" 里下载! 一.项目简述 功能: 主页显示商品: 所有二手书商品展示,可进行商品搜索: 点击商品进入商品详情页,具有立即购买和加入购物车功能,可增减购买 ...

  9. Java项目:在线服装销售商城系统(java+SpringBoot+Maven+Vue+mysql)

    源码获取:博客首页 "资源" 里下载! 一.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclis ...

最新文章

  1. PostgreSQL 10.1 手册_前言_2. PostgreSQL简史
  2. STM32 进阶教程 2 - micropython 使用
  3. api如何使用_什么是API, API是如何工作的?
  4. WordCount by C# 结对编程
  5. java绘制半透明图片_如何使绘制的图像在Java中透明
  6. python代码设计测试用例_[CP_01] Python循环结构案例:模拟银行存取款业务,设计执行测试用例...
  7. Axure经典案例下载(crm需求文档+web端交互组件+Axure移动端模板+管理后台框架模板)
  8. Mysql 存储过程实现订单流水号
  9. php讲一个数组分割成字符串,PHP 分割字符串函数把字符串分割成数组示例
  10. SQL学习笔记04 极客时间 SQL必知必会50讲
  11. 微信公众平台、微信开放平台的关系
  12. math ceil函数python_Python ceil函数
  13. 分辨率不低于300dpi怎么调?如何快速修改图片分辨率?
  14. 完爆90%的性能毛病,收好数据库优化八大通用绝招
  15. 读《透过结构看世界》
  16. FreeModbus-移植到stm32f103
  17. Cookie存储url防止转义,后台解析url执行ulr重定向,跳转指定的url
  18. 《软件供应商手册:SBOM的生成和提供》解读
  19. NewYorkCityAirbnb房源分析(项目练习_4)
  20. 日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个 嫌疑犯的一个。以下为4个嫌疑犯的供词。

热门文章

  1. 在Ubuntu 16.0.4.5 LTS上安装python 2.7版本的cv2模块
  2. shell设置系统环境变量的问题
  3. tree类型题目需要用到的头文件tree.h
  4. Blender车辆绑定动画制作视频教程
  5. 性能测试八:jmeter进阶之beanshell
  6. python Django 学习笔记
  7. python框架之Flask基础篇(一)
  8. opencv下指定文件夹下的图片灰度化(图片的读取与保存)-------简单记录
  9. javascript网页开发 第二章
  10. 深入浅出SpringBoot源码分析