目录
一、shiro授权角色、权限
授角色:用户具备哪些角色
SELECT roleid from t_shiro_user u,t_shiro_user_role ur
where u.userid = ur.userid and u.username = 'zs'
授权限:用户具备哪些权限:
SELECT rp.perid from t_shiro_user u, t_shiro_user_role ur,t_shiro_role_permission rp
where u.userid = ur.userid and ur.roleid= rp.roleid and u.username = 'ls'
1.1、Shiro授权步骤
1.1.1Mapper层、service层
UserMapper.xml
<select id="selelctRoleIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String">
select roleid from t_shiro_user u,t_shiro_user_role ur
where u.userid = ur.userid and u.username = #{userName}
</select>
<select id="selelctPerIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String">
select rp.perid from t_shiro_user u,t_shiro_user_role ur,t_shiro_role_permission rp
where u.userid = ur.userid and ur.roleid = rp.roleid and u.username = #{userName}
</select>
UserMapper
package com.zwc.ssm.mapper;
import com.zwc.ssm.model.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Set;
@Repository
public interface UserMapper {
int deleteByPrimaryKey(Integer userid);
int insert(User record);
int insertSelective(User record);
User selectByPrimaryKey(Integer userid);
//通过 账户名 查询用户信息
User queryUserByUserName(@Param("userName") String userName);
//通过 账户名 查询对应的角色信息
Set<String> selelctRoleIdsByUserName(@Param("userName") String userName);
//通过 账户名 查询对应的权限信息
Set<String> selelctPerIdsByUserName(@Param("userName") String