lxw
2023-12-20 29ca02d4ec7a0f0b50f28a9ab3f69f260207d0cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.whyc.util;
 
import com.whyc.pojo.db_user.UserInf;
import org.apache.shiro.SecurityUtils;
 
/**
 * 从Shiro中直接获取用户信息
 */
public class UserUtil {
 
    public static UserInf getUser(){
 
        UserInf principal = (UserInf) SecurityUtils.getSubject().getPrincipal();
        if(principal == null){
            UserInf user = new UserInf();
            user.setUname("未登录的用户账号");
            user.setUid(0);
            user.setUdownloadRole(0);
            return user;
        }else {
            return principal;
        }
    }
}