io.github.jinghui70.rainbow.dbaccess.enumSupport.CodeEnum Maven / Gradle / Ivy
package io.github.jinghui70.rainbow.dbaccess.enumSupport;
import java.util.Arrays;
import java.util.Objects;
/**
* 标记枚举值在存到数据库的时候,保存其 code
*/
public interface CodeEnum {
String code();
static & CodeEnum> T codeToEnum(Class enumClass, String code) {
return Arrays.stream(enumClass.getEnumConstants())
.filter(e -> Objects.equals(code, e.code()))
.findAny().orElse(null);
}
}