使用oracle做的数据上传系统后台
kongdeqiang
2026-03-21 b63977ec7120e8d5f8e5b7d1ac9b85be76ad62a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.example.security;
 
import lombok.Data;
 
@Data
public class UserContext {
 
    private Long userId;
 
    private String username;
 
    private String deptCode;
 
    private static final ThreadLocal<UserContext> CONTEXT = new ThreadLocal<>();
 
    public static void setUserContext(UserContext userContext) {
        CONTEXT.set(userContext);
    }
 
    public static UserContext getUserContext() {
        return CONTEXT.get();
    }
 
    public static void clear() {
        CONTEXT.remove();
    }
 
    public static Long getCurrentUserId() {
        UserContext context = getUserContext();
        return context != null ? context.getUserId() : null;
    }
 
    public static String getCurrentDeptCode() {
        UserContext context = getUserContext();
        return context != null ? context.getDeptCode() : null;
    }
}