为枚举类添加 编码->名称 转换方法
parent
f38c958804
commit
19c9225aa0
|
@ -35,4 +35,17 @@ public enum SysApiState {
|
||||||
.map(SysApiState::getCode)
|
.map(SysApiState::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(SysApiState::getInfo)
|
||||||
|
.orElse("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,17 @@ public enum SysCheckState {
|
||||||
.map(SysCheckState::getCode)
|
.map(SysCheckState::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(SysCheckState::getInfo)
|
||||||
|
.orElse("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,17 @@ public enum SysDBType {
|
||||||
.map(SysDBType::getCode)
|
.map(SysDBType::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(SysDBType::getInfo)
|
||||||
|
.orElse("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,9 @@ public enum SysPayType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数转换,从支付方式编码转换为支付方式名称
|
* 参数转换,从编码转换为名称
|
||||||
* @param code 支付方式编码
|
* @param code 编码
|
||||||
* @return 支付方式名称
|
* @return 名称
|
||||||
*/
|
*/
|
||||||
public static String getInfoByCode(String code){
|
public static String getInfoByCode(String code){
|
||||||
return Arrays.stream(values())
|
return Arrays.stream(values())
|
||||||
|
|
|
@ -32,4 +32,17 @@ public enum SysYesNo {
|
||||||
.map(SysYesNo::getCode)
|
.map(SysYesNo::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(SysYesNo::getInfo)
|
||||||
|
.orElse("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,5 @@ public enum UserStatus {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,6 +692,7 @@ public class Convert {
|
||||||
public static String str (Object obj, String charsetName) {
|
public static String str (Object obj, String charsetName) {
|
||||||
try{
|
try{
|
||||||
return str(obj, Charset.forName(charsetName.isEmpty()? Constants.UTF8 : charsetName));
|
return str(obj, Charset.forName(charsetName.isEmpty()? Constants.UTF8 : charsetName));
|
||||||
|
// return str(obj, Charset.forName(charsetName));
|
||||||
}catch (Exception exception){
|
}catch (Exception exception){
|
||||||
log.error("字符转换异常: [{}-{}] -> {}",obj,charsetName,exception.getMessage(),exception);
|
log.error("字符转换异常: [{}-{}] -> {}",obj,charsetName,exception.getMessage(),exception);
|
||||||
throw new RuntimeException(exception);
|
throw new RuntimeException(exception);
|
||||||
|
|
Loading…
Reference in New Issue