BigInteger的权限设计

通过储存菜单权限的一个字段(id自定义也是可以的)

1 将选中菜单树的id转换成字符数组的形式,

进行BigInteger对权限进行2的权的和计算

public static BigInteger sumRights(String[] rights){
        BigInteger num = new BigInteger("0");
        for(int i=0; i<rights.length; i++){
            num = num.setBit(Integer.parseInt(rights[i]));
        }
        return num;
    }

将上面的到的num存入到,角色的一个字段中

在校验权限的过程中将之前存入的字段入参为sum

public static boolean testRights(BigInteger sum,String targetRights){
        return testRights(sum,Integer.parseInt(targetRights));
    }

直接的结果返回true或false

通过判断返回的Boolean值来显示菜单

猜你喜欢

转载自www.cnblogs.com/oldzhang1222/p/9298881.html