1.switch搭配枚举

2.根据传入的type来转化枚举

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@Getter
@AllArgsConstructor
public enum ScoreTypeEnum {

NOW_YEAR(1, "今年"),

YEAR(2, "指定年"),

MONTH(3, "指定月(今年某月)"),

YEAR_MONTH(4, "指定年月")

;

private final int type;

private final String desc;

public static ScoreTypeEnum getType(Integer type){
return Arrays.stream(ScoreTypeEnum.values()).filter(scoreTypeEnum -> type.equals(scoreTypeEnum.getType())).findFirst().orElse(null);
}
}