# 第六阶段模块五SSM单体架构项目(下) **Repository Path**: leibranch/phase_6module_5SSM_two ## Basic Information - **Project Name**: 第六阶段模块五SSM单体架构项目(下) - **Description**: 第六阶段模块五作业 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-27 - **Last Updated**: 2021-07-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SSM项目作业 ## 1.完成资源分类管理功能 ### 1.1 需求分析 1) 权限管理模块 展示资源列表页面,有一个资源分类按钮. ![](图片\01.jpg) 2) 点击资源分类,跳转到资源分类页面,对资源分类数据进行维护(增删改查). ![](图片\02.jpg) 3) 后台对应的数据库表为: 资源分类表. ![](图片\03.jpg) ### 1.2 接口文档 请同学们按照接口文档要求完成资源分类模块的数据维护 #### 1.2.1 资源分类信息查询 - 名称: **findAllResourceCategory** - 描述: 查询资源分类信息 - URL: http://localhost:8080/ssm_web/ResourceCategory/findAllResourceCategory - 请求方式: GET - 请求示例 ``` http://localhost:8080/ssm_web/ResourceCategory/findAllResourceCategory ``` - 响应参数示例 ```json { "success": true, "state": 200, "message": "响应成功", "content": [{ "id": 1, "name": "角色管理", "sort": 1, "createdTime": 1595230906000, "updatedTime": 1595230906000, "createdBy": "system", "updatedBy": "system" }, { "id": 2, "name": "菜单管理", "sort": 2, "createdTime": 1595230906000, "updatedTime": 1595230906000, "createdBy": "system", "updatedBy": "system" }, { "id": 3, "name": "资源管理", "sort": 3, "createdTime": 1595230906000, "updatedTime": 1595230906000, "createdBy": "system", "updatedBy": "system" }......] } ``` #### 1.2.2 添加&修改资源分类 - 名称: **saveOrUpdateResourceCategory** - 描述: 添加& 修改资源分类接口 - URL: http://localhost:8080/ssm_web/ResourceCategory/saveOrUpdateResourceCategory - 请求方式: POST - 请求示例 ``` //新增 { name: "作业管理", sort: 1 } //修改 { id: 10, name: "家庭作业管理", sort: "2" } ``` **响应参数** | 参数名称 | 参数说明 | 类型 | schema | | -------- | -------- | -------------- | -------------- | | success | | boolean | | | state | | integer(int32) | integer(int32) | | message | | string | | | content | | object | | #### 1.2.3 删除资源分类 - 名称: **deleteResourceCategory** - 描述: 删除资源分类接口 - URL: http://localhost:8080/ssm_web/ResourceCategory/deleteResourceCategory - 请求方式: GET - 请求示例 ``` http://10.1.194.181:8080/ssm_web/ResourceCategory/deleteResourceCategory?id=10 ``` - 响应数据 | 参数名称 | 参数说明 | 类型 | schema | | -------- | -------- | -------------- | -------------- | | success | | boolean | | | state | | integer(int32) | integer(int32) | | message | | string | | | content | | object | | ## 2.完成为角色分配资源功能 ### 1.1 需求分析 1) 权限管理模块的角色列表页面, 可以为角色分配资源 ![](图片\04.jpg) 2) 当选中某个角色,点击分配资源时,就会显示该角色当前拥有的资源权限信息 - 例如: 点击课程管理员的分配资源 按钮,会显示课程管理员拥有哪些的资源权限的信息 ![](图片\05.jpg) - 课程管理员所拥有的是课程管理资源分类下的资源权限 ![](图片\06.png) ### 1.2 接口文档 #### 1.2.1 查询资源分类信息 - 在资源模块的讲解中,我们已经完成了这个接口 #### 1.2.2 资源信息分页 - 在资源模块的讲解中,我们已经完成了这个接口 - 前端需要这两组数据,进行资源列表的展示,所以一定要完成这两个功能 ![](图片\06.jpg) #### 1.2.3 获取当前角色拥有的 资源信息 - 名称: **findResourceListByRoleId** - 描述: 添加& 修改资源分类接口 - URL: http://localhost:8080/ssm_web/role/findResourceListByRoleId - 请求方式: GET - 请求示例 ``` http://10.1.194.181:8080/ssm_web/role/findResourceListByRoleId?roleId=3 ``` - 响应数据示例 ``` { "success": true, "state": 200, "message": "响应成功", "content": [{ "id": 4, "name": "课程管理", "sort": null, "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null, "resourceList": [{ "id": 33, "name": "课程上下架", "url": "/boss/course/changeState", "categoryId": 4, "description": "课程上下架", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 34, "name": "新建课程页面路由", "url": "/#/courses/new", "categoryId": 4, "description": "新建课程页面路由", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 35, "name": "通过课程Id获取课程信息", "url": "/boss/course/getCourseById", "categoryId": 4, "description": "通过课程Id获取课程信息", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 36, "name": "分页查询课程信息", "url": "/boss/course/getQueryCourses", "categoryId": 4, "description": "分页查询课程信息", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 37, "name": "保存或者更新课程信息", "url": "/boss/course/saveOrUpdateCourse", "categoryId": 4, "description": "保存或者更新课程信息", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 38, "name": "上传图片", "url": "/boss/course/upload", "categoryId": 4, "description": "上传图片", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 39, "name": "保存活动商品", "url": "/boss/activityCourse/save", "categoryId": 4, "description": "保存活动商品", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 40, "name": "更新活动商品状态", "url": "/boss/activityCourse/updateStatus", "categoryId": 4, "description": "更新活动商品状态", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 41, "name": "获取章节", "url": "/boss/course/section/getBySectionId", "categoryId": 4, "description": "获取章节", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 42, "name": "获取章节和课时", "url": "/boss/course/section/getSectionAndLesson", "categoryId": 4, "description": "获取章节和课时", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 43, "name": "保存或更新章节", "url": "/boss/course/section/saveOrUpdateSection", "categoryId": 4, "description": "保存或更新章节", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 44, "name": "获取课时内容", "url": "/boss/course/lesson/getById", "categoryId": 4, "description": "获取课时内容", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }, { "id": 45, "name": "保存或更新课时", "url": "/boss/course/lesson/saveOrUpdate", "categoryId": 4, "description": "保存或更新课时", "createdTime": null, "updatedTime": null, "createdBy": null, "updatedBy": null }] }] } ``` ##### > 步骤提示 - 实体类 - 在ResourceCategory类中,有一个集合,泛型为Resource,来表示一对多关系 ```java //资源集合 一对多 private List resourceList = new ArrayList<>(); ``` - dao层 - 在RoleMapper中需要编写两个方法 - 方法1: 查询当前角色拥有的资源分类信息 - 方法2: 查询当前角色拥有的资源信息 - service层 - 调用dao中的两个方法分别获取资源分类数据和资源数据 - 将资源数据封装到对应的分类下 - web层 - 编写一个接口,参数为 角色id - 根据角色id 查询当前角色拥有的资源信息,并返回 #### 1.2.4 为角色分配菜单 - 名称: **findResourceListByRoleId** - 描述: 添加& 修改资源分类接口 - URL: http://localhost:8080/ssm_web/role/roleContextResource - 请求方式: POST - 请求示例 ``` { roleId: 5, resourceIdList: [1, 2, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] } roleId: 角色id resourceIdList: 要分配的资源id ``` - 响应结果示例 | 参数名称 | 参数说明 | 类型 | schema | | -------- | -------- | -------------- | -------------- | | success | | boolean | | | state | | integer(int32) | integer(int32) | | message | | string | | | content | | object | | ##### > 步骤提示 - 实体类 - 创建 RoleResourceRelation类 ```java public class RoleResourceRelation{ } ``` - RoleResourceRelation对应的是 role_resource_relation表,该表是一张中间表,记录了角色与资源的对应关系 - dao层 - dao层需要编写两个方法 - 方法1 根据角色ID 删除角色与资源的关联关系(操作中中间表 role_resource_relation) - 方法2 为角色分配资源, 删除完成后 ,插入最新的关联关系 - service层 - 编写一个为角色分配资源的方法 - 先清空之前的关联关系 - 第二步 补全信息,插入新的关联关系 - web层 - 创建一个VO类: RoleResourceVo,用来接收 角色ID 与 资源ID集合 ```java public class RoleResourceVo { private Integer roleId; private List resourceIdList; get/set ...... } ``` - 将接收的数据,交给service处理