1.说明

只讲解关键部分,详细看源码,文章下方捐赠或QQ联系捐赠获取。

2.功能展示


3.业务模型

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_dept")
public class SysDept implements Serializable { private static final long serialVersionUID = 1L; @TableId(value = "id", type = IdType.AUTO)
private Integer id; /**
* 上级部门ID
*/
private Integer pid; /**
* 所有上级部门ID, 0为根,格式:0,1,2,
*/
private String pids; /**
* 部门名称
*/
private String deptName; /**
* 部门编码
*/
private String deptCode; @TableField(exist=false)
private String pname; /**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime; /**
* 创建人
*/
private String createUser; /**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime; /**
* 修改人
*/
private String updateUser; }

4.控制器

@Controller
@RequestMapping("/sysDept/")
public class SysDeptController {
@Autowired
private SysDeptService sysDeptService; @GetMapping("listUI")
public String listUI() {
return "dept/list";
} @RequestMapping("form")
public String form(Map<String,Object> map) {
return "dept/form";
} @GetMapping("toSelectTree")
public String toSelectTree() {
return "dept/selectTree";
} @PostMapping("list")
@ResponseBody
public Result<IPage<SysDept>> list(@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
// 构造分页查询条件
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>(); Page<SysDept> page = new Page<>(pageNo,pageSize); IPage<SysDept> result = sysDeptService.selectDeptList(page, null);
// 设置总记录数
result.setTotal(sysDeptService.count(queryWrapper)); sysDeptService.count(queryWrapper);
return ResultUtil.ok(result);
} @GetMapping("listTree")
@ResponseBody
public Object listTree() {
// User user = getUserEntity();
// 构建查询条件,从根查找
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
// queryWrapper.like("pids", user.getDept().getPids()+user.getDeptId()).or().eq("id",user.getDeptId());
queryWrapper.like("pids", 0);
List<SysDept> list = sysDeptService.list(queryWrapper);
return list;
} @OperLog(operModule = "部门管理",operType = "修改",operDesc = "修改部门")
@PostMapping("save")
@ResponseBody
public Result<String> add(@RequestBody SysDept dept){
// 新增
if(dept.getId()==null){
dept.setCreateTime(new Date());
dept.setCreateUser("TODO");
}
// 设置上级部门ID
if(dept.getPid()!=0){
// 获取上级部门的ids然后拼接上级部门id
SysDept parentDept = sysDeptService.getById(dept.getPid());
dept.setPids(parentDept.getPids()+dept.getPid()+",");
}
if(!sysDeptService.saveOrUpdate(dept)){
return ResultUtil.fail("添加失败");
}
return ResultUtil.ok("添加成功");
} @OperLog(operModule = "部门管理",operType = "删除",operDesc = "删除部门")
@PostMapping("/remove")
@ResponseBody
public Result<String> remove(@RequestParam Integer id){
sysDeptService.removeById(id); return ResultUtil.ok("删除成功!");
} @RequestMapping(value="{id}/select",method= RequestMethod.GET)
public String select(Map<String,Object> map,@PathVariable Integer id) {
SysDept sysDept = sysDeptService.getById(id);
map.put("record",sysDept);
return "sysDept/edit";
}

5.前端页面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="utf-8">
<title>部门列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" th:href="@{/static/plugin/layui/css/layui.css}" media="all">
</head>
<body>
<table class="layui-hide" id="SysDept" lay-filter="SysDept"></table> <input type="text" id="ctx" hidden="hidden" th:value="${#request.getContextPath()}"> <!--编辑表单-->
<div class="layui-row" id="editForm" style="display:none;">
<div class="layui-col-md10">
<form class="layui-form layui-from-pane" action="" style="margin-top:20px">
<input type="text" id="id" name="id" hidden="hidden">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">上级部门</label>
<div class="layui-input-inline">
<input type="text" id="pname" name="pname" required lay-verify="required" autocomplete="off"
placeholder="" class="layui-input">
</div>
<button class="layui-btn layui-btn-sm" id="chooseDeptBtn" type="button">
<i class="layui-icon"></i>
</button>
<input type="hidden" id="pid" name="pid"/>
</div>
<div class="layui-inline">
<label class="layui-form-label">部门名称</label>
<div class="layui-input-inline">
<input type="text" id="deptName" name="deptName" required lay-verify="required" autocomplete="off"
placeholder="" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">部门编码</label>
<div class="layui-input-inline">
<input type="text" id="deptCode" name="deptCode" required lay-verify="required" autocomplete="off"
placeholder="" class="layui-input">
</div>
</div>
</div> <div class="layui-form-item" style="margin-top:40px">
<div class="layui-input-block">
<button class="layui-btn layui-btn-submit " lay-submit="" lay-filter="confirm">确认</button>
<button type="button" class="layui-btn layui-btn-primary" id="back">关闭</button>
</div>
</div>
</form>
</div>
</div> <script type="text/html" id="deptToolBar">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="add" shiro:hasPermission="dept:add">新增</button>
</div>
</script> <script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit" shiro:hasPermission="dept:edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" shiro:hasPermission="dept:remove">删除</a>
</script>

6 获取源码

捐赠任意金额,评论区留下邮箱发送 :)

SpringBoot+Shiro+LayUI权限管理系统项目-4.实现部门管理的更多相关文章

  1. SpringBoot框架的权限管理系统

    springBoot框架的权限管理系统,支持操作权限和数据权限,后端采用springBoot,MyBatis,Shiro,前端使用adminLTE,Vue.js,bootstrap-table.tre ...

  2. SpringBoot&Shiro实现权限管理

    SpringBoot&Shiro实现权限管理 引言 相信大家前来看这篇文章的时候,是有SpringBoot和Shiro基础的,所以本文只介绍整合的步骤,如果哪里写的不好,恳请大家能指出错误,谢 ...

  3. Asp.Net Core 项目实战之权限管理系统(6) 功能管理

    0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...

  4. SpringBoot+Shiro学习(七):Filter过滤器管理

    SpringBoot+Shiro学习(七):Filter过滤器管理 Hiwayz 关注  0.5 2018.09.06 19:09* 字数 1070 阅读 5922评论 1喜欢 20 先从我们写的一个 ...

  5. spring boot + mybatis + layui + shiro后台权限管理系统

    后台管理系统 版本更新 后续版本更新内容 链接入口: springboot + shiro之登录人数限制.登录判断重定向.session时间设置:https://blog.51cto.com/wyai ...

  6. niaobulashi-一个基于springboot shrio的权限管理系统

    github项目地址:https://github.com/niaobulashi/niaobulashi springboot学习地址:http://www.ityouknow.com/spring ...

  7. .NET Core/.NET5/.NET6 开源项目汇总5:权限管理系统项目

    系列目录     [已更新最新开发文章,点击查看详细] 企业管理系统一般包含后台管理UI.组织机构管理.权限管理.日志.数据访问.表单.工作流等常用必备功能.下面收集的几款优秀开源的管理系统,值得大家 ...

  8. 基于easyUI实现权限管理系统(三)——角色管理

    此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 相关文件介绍 1. role.jsp:角色管理界面 <!DOCTYPE html PUBLIC "-//W3 ...

  9. springboot + shiro 构建权限模块

    权限模块基本流程 权限模块的基本流程:用户申请账号和权限 -->登陆认证 -->安全管控模块认证 -->调用具体权限模块(基于角色的权限控制) --> 登陆成功 -->访 ...

  10. 基于easyUI实现权限管理系统(四)——用户管理

    此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 相关文件介绍 1. user.jsp:用户管理界面 <!DOCTYPE html PUBLIC "-//W3 ...

随机推荐

  1. Android——SQLiteOpenHelper

    使用步骤: 新建一个继承自SQLiteOpenHelper的数据库操作类,提示重写onCreate和OnUpgraed两个方法.其中,onCreate方法只在第一次打开数据库时执行,在此可进行表结构创 ...

  2. 2021-10-13Docker

    一.简介 1.技术前提 了解linux 修改虚拟机ip为静态: vim /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="stati ...

  3. Go-连接redis

  4. Django应用中的静态文件处理

    在日常开发中,我们都是把Django的Debug模式打开,方便调试,在这个模式下,由Django内置的Web服务器提供静态文件服务,不过需要进行一些配置,才能正确访问. 配置settings # St ...

  5. [转帖]调试springboot数据库系统应用时常用debug日志配置, 解决问题缩小范围时常用

    https://www.yihaomen.com/article/1853.html 摘要: 用 spring boot 开发应用时,在遇到麻烦问题时,经常会打开debug日志,下面记录一个通用的思路 ...

  6. [转帖]Chrome 109发布,最后一个支持Windows 7/8的版本

    https://www.163.com/dy/article/HQR3QQFD0511CUMI.html 出品 | OSC开源社区(ID:oschina2013) Google 在去年 12 月 1 ...

  7. [转帖]细说Redis监控和告警

    https://blog.csdn.net/sD7O95O/article/details/78096956 对于任何应用服务和组件,都需要一套完善可靠谱监控方案.尤其redis这类敏感的纯内存.高并 ...

  8. [转帖]一次操作系统报错OutOfMemory Error的处理记录

    在启动公司内嵌的tomcat容器时出现报错, 如下: # There is insufficient memory for the Java Runtime Environment to contin ...

  9. vue3中markRaw的使用

    markRaw 作用:将一个对象标记为不可以被转化为代理对象.返回该对象本身. 应用场景: 1.有些值不应被设置成响应式时,例如复杂的第三方类库等 2.当渲染具有不可变数据源的大列表时,跳过响应式转换 ...

  10. Go 跟踪函数调用链,理解代码更直观

    Go 跟踪函数调用链,理解代码更直观 目录 Go 跟踪函数调用链,理解代码更直观 一.引入 二.自动获取所跟踪函数的函数名 三.增加 Goroutine 标识 四.让输出的跟踪信息更具层次感 五.利用 ...