利用枚举,得到类型的字段

枚举类:

 

package com.yzf.cloud.funds.model.enums;

public enum ReceiptTypeEnum {

	OUTPUTINVOICE("销项发票", 1), INCOMINVOICE("进项发票", 2), OTHERINVOICE("其他发票", 3), BANKJOURNAL("银行日记账",
			4), CASHJOURNAL("现金日记账", 5), CERTIFIEDINVOICE("认证发票", 6);

	private String desc;
	private int value;

	private ReceiptTypeEnum(String desc, int value) {
		this.desc = desc;
		this.value = value;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public static String getDesc(int value) {
     for (ReceiptTypeEnum receiptTypeEnum : ReceiptTypeEnum .values()) {
      if (value== receiptTypeEnum .getValue()) {
        return receiptTypeEnum .getDesc();
      }
    }
		return "";
	}
}


获取对应的 值:

 

 

ReceiptTypeEnum.OUTPUTINVOICE.getValue();//得到序号
ReceiptTypeEnum.OUTPUTINVOICE.getDesc();//得到字段
ReceiptTypeEnum.getDesc(receiptType);//得到序号对应的字段

 

 

 

 

 

你可能感兴趣的:(java,enum)