枚举-根据value获取枚举


public enum MallType {
  TAOBAO("1001","淘宝商城"),
  TMALL("1002","天猫商城"),
  ;

  private final String caption;
  private final String code;

  MallType(String code,String caption) {
    this.caption = caption;
    this.code = code;
  }


  public String caption() {
    return this.caption;
  }
  public String code() {
    return this.code;
  }

  public static MallType byCode(String code) {
    MallType[] mallTypeEnums = values();
    for (MallType mallTypeEnum : mallTypeEnums) {
      if (mallTypeEnum.code().equals(code)) {
        return mallTypeEnum;
      }
    }
    return null;
  }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM