Blame view

Localstorage.java 955 Bytes
涂亚平 committed
1 2 3 4
package com.subsidy.util;

import org.springframework.web.bind.annotation.RestController;

涂亚平 committed
5 6 7
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

涂亚平 committed
8 9 10
@RestController
public class Localstorage {
    private static final ThreadLocal<Object> local = ThreadLocal.withInitial(() -> null);
涂亚平 committed
11 12 13 14 15 16 17
    private static ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
    public static void setUser(Object obj, String type) {
//        Map<String, Object> map = new HashMap<>();
        map.put("user", obj);
        map.put("type", type);
        Localstorage.local.set(map);
    }
涂亚平 committed
18

涂亚平 committed
19 20
    public static Map<String, Object> getMap() {
        return (Map<String, Object>) Localstorage.local.get();
涂亚平 committed
21 22 23
    }

    public static Object getUser() {
涂亚平 committed
24 25
//        Map<String, Object> map = (Map<String, Object>) Localstorage.local.get();
        return map.get("user");
涂亚平 committed
26 27 28 29 30 31
    }

    public static void remove() {
        Localstorage.local.remove();
    }
}