首页 > 其他分享 >SpringBoot 02 shiro框架查询用户权限与角色

SpringBoot 02 shiro框架查询用户权限与角色

时间:2023-10-17 16:56:31浏览次数:37  
标签:02 String private ur role ro id shiro SpringBoot

 

 实体类 

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("t_user")
public class RUser {
    @TableId(value="id",type = IdType.AUTO)
    private Integer usrId;
    private String usrName;
    private  String usrAccount;
    private  String  usrPassword;
    private  String  usrSalt;
    private  String  usrClazz;
@TableField(exist = false)
private Set<Role> roleSet;
}
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("t_role")
public class Role {
    @TableId(value="ro_id",type = IdType.AUTO) //告诉主键
    private Integer roId;//默认驼峰命名

    private String roLabel;
    @TableField(exist = false)
private Set<Perm> permSet;
}
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("t_perm")
public class Perm {
    @TableId(value="pm_id",type = IdType.AUTO)
    private Integer pmId;
    private String pmLabel;
}

 

Mapper

@Mapper
public interface RUserMapper extends BaseMapper<RUser> {
    List<RUser> selectListByAccount(String usrAccount);
}
@Mapper
public interface RoleMapper extends BaseMapper<Role> {//只有单表查询的方法,多表查询要自己写
    Role selectByLable(String roLabel);
}

Mapper.xml

RUserMapper.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="com.mapper.RUserMapper">
    <select id="selectListByAccount" resultMap="rmUser">
        select * from t_user u,t_user_role ur,t_role r where ur.ur_ro_id=r.ro_id
                                                         and u.usr_id=ur.ur_usr_id
                                                         and usr_account=#{usrAccount}
    </select>
        <resultMap id="rmUser" type="RUser">
        <id property="usrId" column="usr_id"/>
        <result property="usrName" column="usr_name"/>
        <result property="usrAccount" column="usr_account"/>
        <result property="usrSalt" column="usr_salt"/>
        <result property="usrClazz" column="usr_clazz"/>
        <result property="usrPassword" column="usr_password"/>
        <collection property="roleSet" ofType="Role"><!--property:实体类的集合属性名 ofType:集合泛型-->
            <id property="roId" column="ro_id"/>
            <result property="roLabel" column="ro_label"/>
        </collection>
    </resultMap>


</mapper>

RoleMapper.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="com.mapper.RoleMapper">
      <select id="selectByLable" resultMap="labRole">
        select * from t_role r,t_role_perm rp,t_perm p
        where r.ro_id=rp.rp_ro_id
          and rp.rp_pm_id=p.pm_id
          and ro_label in (#{roLabel})
    </select>
    <resultMap id="labRole" type="Role">
        <id property="roId" column="ro_id"/>
        <result property="roLabel" column="ro_label"/>
        <collection property="permSet" ofType="Perm">
            <id property="pmId" column="pm_id"/>
            <result property="pmLabel" column="pm_label"/>
        </collection>
    </resultMap>
</mapper>

 

test

 

 

 

 

标签:02,String,private,ur,role,ro,id,shiro,SpringBoot
From: https://www.cnblogs.com/oyww-2027/p/17770123.html

相关文章

  • 2023年石门中学NOIP模拟测试(2023.10.17)
    原题大战,还是\(4\)道计数...放个头图:一蓝一紫两黑,简单且原题0.o?出模拟赛搬原题演都不演了,他真的我哭死。那这总结不写也罢T1\(n\leq10^3\)。简单来说,要选出子序列满足相同颜色连续的方案数。签到题,但写了\(\text{1h}\)的我是sb。直接大力状压,设\(dp_{i,s,c}\)表......
  • 2023.10.14 总结
    T1题面:给\(n\)个数染色,要求使\(|i-j|\)为质数的两个数染的色不能一样,求任意一种染色方法。\(n\le6\)时直接打表,之后模拟一下。容易发现,\(2\)是质数中唯一一个偶数,所以我们可以\(1234\)连续染色,由于\(4\)是偶数且大于\(2\),所以差为质数的颜色不会相等。最后输出......
  • Newstar CTF 2023 week2 pwn
    1.ret2libc发现存在poprdi观察main函数,可以利用puts函数泄露libcfrompwnimport*fromLibcSearcherimport*context(os="linux",arch="amd64",log_level="debug")elf=ELF('/home/miyu/Desktop/ret2libc')p=remote("node4.b......
  • SpringBoot应用jar包启动原理详解
    1、maven打包SpringBoot项目的pom.xml文件中默认使用spring-boot-maven-plugin插件进行打包:<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId>&l......
  • Windows Server 2016 OVF, updated Oct 2023 (sysin) - VMware 虚拟机模板
    WindowsServer2016OVF,updatedOct2023(sysin)-VMware虚拟机模板2023年10月版本更新,现在自动运行sysprep,支持ESXiHostClient部署请访问原文链接:https://sysin.org/blog/windows-server-2016-ovf/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org现在......
  • Windows Server 2019 OVF, updated Oct 2023 (sysin) - VMware 虚拟机模板
    WindowsServer2019OVF,updatedOct2023(sysin)-VMware虚拟机模板2023年10月版本更新,现在自动运行sysprep,支持ESXiHostClient部署请访问原文链接:https://sysin.org/blog/windows-server-2019-ovf/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgWind......
  • Matlab 2023a 中文版 下载安装及永久激活教程!
    软件介绍:MATLABR2023a是一款由MathWorks公司开发的著名专业编程和数学计算软件,为用户提供了一个高效、灵活和易用的环境,用于进行数值计算、数据可视化、算法开发、数据分析等任务。 安装和使用教程:1.通过文章末尾处下载软件后,选中下载的【Matlab2023a】压缩包,右击选择解压到【Ma......
  • 通知|2023年8月PMP认证考试成绩公布啦!
    2023年8月PMP®、PMI-ACP®、PMI-PBA®、PgMP®考试终于公布啦! 从2023年10月16日(美国东部时间)开始,2023年8月中国大陆考试的成绩将于大约一周内上传到PMI网站! 成绩是分批出的,如果暂时没查到成绩的同学请耐心等待,预计一周内成绩会全部出来。  如何查询考试成绩?1、收到PMI邮件提......
  • 2023年下半年软考考前注意事项!一定要看!
    2023年下半年软考将于11月4-5日开考,由于首次实行机考,开考批次划分各地可能不同,所以具体考试时间请以准考证为准,请考生尽早打印准考证,了解考试时间、地点、考场规则等具体要求。  1、准考证打印时间虽然大部分地区准考证打印时间在报名通知中有公布,但是由于实行机考,考试批次划分等......
  • 【GJOI 2023.10.17 T4】 莫队
    莫队今天,接触信息学不久的小A刚刚学习了莫队。莫队可以解决一类难以合并,但方便插入的信息维护。比如,给定一个序列,支持单点修改,每次询问一个区间出现了多少种数字。再比如,给定一个序列,支持单点修改,每次询问区间众数。诸如此类。小A觉得这样的情况太平凡了。于是,他定义了一个......