使用oracle做的数据上传系统后台
kongdeqiang
2026-03-23 79619d4274f3bb8d4b90a0e7ddafc17e3c9028bf
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
38
39
40
41
42
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;
    }
 
    public static String getCurrentUsername() {
        UserContext context = getUserContext();
        return context != null ? context.getUsername() : null;
    }
}