dangsn
2024-06-06 33321f5486fd586fda6fd3f46b7e71754fede28b
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.vci.starter.web.enumpck;
 
/**
 * 会话信息存储的方式,实际上和spring-session的管理方式是一样的,但是为了兼容以前的项目,又重复造了轮子
 * @author weidy
 * @date 2020/2/5
 */
public enum SessionStorageTypeEnum implements BaseEnum {
    /**
     * redis管理
     */
    REDIS("redis","缓存"),
 
    /**
     * 数据库
     */
    DATABASE("database","数据库");
 
    /**
     * 值
     */
    private String value;
 
    /**
     * 显示文本
     */
    private String text;
 
    @Override
    public String getValue() {
        return value;
    }
 
    @Override
    public String getText() {
        return text;
    }
 
    public void setValue(String value) {
        this.value = value;
    }
 
    public void setText(String text) {
        this.text = text;
    }
 
    private SessionStorageTypeEnum(String value,String text){
        this.value = value;
        this.text = text;
    }
 
    /**
     * 根据名称获取对应的枚举值
     * @param text 名称
     * @return 枚举值
     */
    public static String getValueByText(String text){
        for(SessionStorageTypeEnum wenum : SessionStorageTypeEnum.values()){
            if(wenum.getText().equalsIgnoreCase(text)){
                return wenum.getValue();
            }
        }
        return "";
    }
 
    /**
     * 根据枚举值获取名称
     * @param value 枚举值
     * @return 名称
     */
    public static String getTextByValue(String value){
        for(SessionStorageTypeEnum wenum : SessionStorageTypeEnum.values()){
            if(wenum.getValue().equalsIgnoreCase(value)){
                return wenum.getText();
            }
        }
        return "";
    }
 
    /**
     * 值转换为枚举对象
     * @param value 值
     * @return 如果不符合要求返回Null
     */
    public static SessionStorageTypeEnum forValue(String value){
        for(SessionStorageTypeEnum wenum : SessionStorageTypeEnum.values()){
            if(wenum.getValue().equalsIgnoreCase(value)){
                return wenum;
            }
        }
        return SessionStorageTypeEnum.REDIS;
    }
}