011.开发RBACModel层(了解某一个用户能使用那些功能)
1.增加rbac.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="rbacmapper"> <select id="selectNodeByUserId" parameterType="Long" resultType="com.imooc.oa.entity.Node"> select DISTINCT n.* from sys_role_user ru , sys_role_node rn , sys_node n where ru.role_id = rn.role_id and rn.node_id = n.node_id and ru.user_id = #{value} order by n.node_code </select> </mapper>
2.在src/main/java/com/imooc/oa/entity下增加Node实体类
package com.imooc.oa.entity; public class Node { private Long nodeId; private Integer nodeType;//节点类型 1-模块 2-功能 private String nodeName;//节点名 private String url;//页面URL private Integer nodeCode;//节点编码 private Long parentId;//上级编号 public Long getNodeId() { return nodeId; } public void setNodeId(Long nodeId) { this.nodeId = nodeId; } public Integer getNodeType() { return nodeType; } public void setNodeType(Integer nodeType) { this.nodeType = nodeType; } public String getNodeName() { return nodeName; } public void setNodeName(String nodeName) { this.nodeName = nodeName; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public Integer getNodeCode() { return nodeCode; } public void setNodeCode(Integer nodeCode) { this.nodeCode = nodeCode; } public Long getParentId() { return parentId; } public void setParentId(Long parentId) { this.parentId = parentId; } }
3.在mybatis-config.xml中注册
<mapper resource="mappers/rbac.xml"/>
4.在src/main/java/com/imooc/oa/mapper增加RbacMapper
package com.imooc.oa.mapper; import com.imooc.oa.entity.Node; import com.imooc.oa.utils.MybatisUtils; import java.util.List; public class RbacMapper { public List<Node> selectNodeByUserId(Long userId){ List list = (List)MybatisUtils.executeQuery(sqlSession -> sqlSession.selectList("rbacmapper.selectNodeByUserId", userId)); return list; } }
5.在src/main/java/com/imooc/oa/service下增加RbacService
package com.imooc.oa.service; import com.imooc.oa.entity.Node; import com.imooc.oa.mapper.RbacMapper; import java.util.List; public class RbacService { private RbacMapper rbacMapper = new RbacMapper(); public List<Node> selectNodeByUserId(Long userId){ return rbacMapper.selectNodeByUserId(userId); } }