增加枚举参数互相转换方法

master
面包骑士 2024-08-08 20:38:26 +08:00
parent c37f9e7256
commit 92ade8267a
1 changed files with 26 additions and 0 deletions

View File

@ -33,4 +33,30 @@ public enum SysPayType {
.map(SysPayType::getCode) .map(SysPayType::getCode)
.anyMatch(c -> c.equals(code)); .anyMatch(c -> c.equals(code));
} }
/**
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.findFirst()
.map(SysPayType::getInfo)
.orElse("-");
}
/**
* ,
* @param info
* @return
*/
public static String getCodeByInfo(String info){
return Arrays.stream(values())
.filter(c -> c.getInfo().equals(info))
.findFirst()
.map(SysPayType::getCode)
.orElse("-");
}
} }