先创建枚举值
import java.util.HashMap;
import java.util.Map;
/**
* @author liziqiang
* @date 2021/4/27
*/
public enum SmsTypeEnum {
SHOPEX_SMS(1, "商派短信"),
ALI_SMS(2, "阿里短信");
private Integer code;
private String name;
SmsTypeEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
public static String getTypeName(Integer code){
for(SmsTypeEnum typeEnum:SmsTypeEnum.values()){
if(code.equals(typeEnum.name())){
return typeEnum.getName();
}
}
return "";
}
public static SmsTypeEnum getEnumByKey(Integer code) {
if (null == code) {
return null;
}
for (SmsTypeEnum temp : SmsTypeEnum.values()) {
if (temp.getCode() == code) {
return temp;
}
}
return null;
}
public static final Map<Integer, String> map = new HashMap();
static {
for (SmsTypeEnum tEnum : SmsTypeEnum.values()) {
map.put(tEnum.getCode(), tEnum.getName());
}
}
}
controller层
@ApiOperation(value = "获取短信类型下拉框", notes = "获取短信类型下拉框")
public CustomRestResult<Map<Integer,String>> getSmsType() {
Map<Integer,String> map = SmsTypeEnum.map;
return CustomRestResult.success(map,"查询成功");
}