微服务 教程
1085个小节阅读:196k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
管理员详情包含管理员的角色,以及角色拥有的权限,所以需要进行多表查询。
编写AdminMapper
xxxxxxxxxx
public interface AdminMapper extends BaseMapper<Admin> {
// 查询用户详情
Admin findDesc(Integer aid);
}
编写AdminMapper.xml
xxxxxxxxxx
<mapper namespace="com.itbaizhan.travel.mapper.AdminMapper">
<resultMap id="adminMap" type="com.itbaizhan.travel.pojo.Admin">
<id property="aid" column="aid"></id>
<result property="username" column="username"></result>
<collection property="roles" column="aid" ofType="com.itbaizhan.travel.pojo.Role">
<result property="roleName" column="roleName"></result>
<result property="roleDesc" column="roleDesc"></result>
<collection property="permissions" column="rid" ofType="com.itbaizhan.travel.pojo.Permission">
<result property="permissionName" column="permissionName"></result>
</collection>
</collection>
</resultMap>
<select id="findDesc" parameterType="int" resultMap="adminMap">
SELECT *
FROM admin
LEFT JOIN admin_role
ON admin.aid = admin_role.aid
LEFT JOIN role
ON admin_role.rid = role.rid
LEFT JOIN role_permission
ON role.rid = role_permission.rid
LEFT JOIN permission
ON role_permission.pid = permission.pid
WHERE admin.aid = #{aid}
</select>
</mapper>
编写AdminService
xxxxxxxxxx
// 查询用户详情
public Admin findDesc(Integer aid){
return adminMapper.findDesc(aid);
}
编写AdminController
xxxxxxxxxx
"/desc") (
public ModelAndView desc(Integer aid){
Admin admin = adminService.findDesc(aid);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("admin", admin);
modelAndView.setViewName("/backstage/admin_desc");
return modelAndView;
}
编写页面admin_desc.html
,展示管理员时我们希望同时展示他的角色和权限,使用AdminLTE的树状表插件非常方便展示。
xxxxxxxxxx
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>用户详情</title>
<th:block th:replace="/backstage/common_resources::common_css"></th:block>
<th:block th:replace="/backstage/common_resources::common_js"></th:block>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<header th:replace="~{/backstage/common_header::header}"></header>
<aside th:replace="~{/backstage/common_aside::aside}"></aside>
<div class="wrapper">
<div class="content-wrapper">
<!-- 内容头部 -->
<section class="content-header">
<h1>
用户管理
<small>用户详情</small>
</h1>
<ol class="breadcrumb">
<li><a href="@{/backstage/index}"><i class="fa fa-dashboard"></i> 首页</a></li>
<li><a href="@{/backstage/admin/all}"> 用户管理</a></li>
<li class="active">用户详情</li>
</ol>
</section>
<!-- 内容头部 /-->
<!-- 正文区域 -->
<section class="content">
<table id="collapse-table" class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>名称</th>
<th>详情</th>
</tr>
</thead>
<tr>
<td th:text="${admin.username}"></td>
</tr>
<tbody th:each="role,status:${admin.roles}">
<tr th:attr="data-tt-id=${status.index}">
<td th:text="${role.roleName}"></td>
<td th:text="${role.roleDesc}"></td>
</tr>
<tr th:each="permission:${role.permissions}" th:attr="data-tt-parent-id=${status.index}" data-tt-id="1-1">
<td th:text="${permission.permissionName}"></td>
<td th:text="${permission.permissionDesc}"></td>
</tr>
</tbody>
</table>
</section>
<!-- 正文区域 /-->
</div>
</div>
<footer th:replace="~{/backstage/common_footer::footer}"></footer>
<script>
$(document).ready(function() {
/*table tree*/
$("#collapse-table").treetable({
expandable: true
});
});
</script>
</body>
</html>
启动项目,测试功能