zzw
1 天以前 781b8b3e072a4e00b1cee56f961280c753cbb460
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.emergencyrepair.common.audit;
 
/**
 * Carries the request user through the current request thread for MyBatis fills.
 */
public final class CurrentUserContext {
    private static final ThreadLocal<String> USERNAME = new ThreadLocal<>();
 
    private CurrentUserContext() {
    }
 
    public static void set(String username) {
        USERNAME.set(username);
    }
 
    public static String get() {
        String username = USERNAME.get();
        return username == null || username.trim().isEmpty() ? "admin" : username.trim();
    }
 
    public static void clear() {
        USERNAME.remove();
    }
}