java 枚举的用法

https://blog.csdn.net/cauchy6317/article/details/82313088(简历介绍)

https://blog.csdn.net/qq_27093465/article/details/52180865(学习了)

https://www.cnblogs.com/wrong5566/p/7132705.html(很简洁)

https://blog.csdn.net/newbie_907486852/article/details/81027512

package com.dictionary;

public enum CatalogTypeDictionary {
	Article(1,"文章"),
	Picture(2,"图片"),
	Product(3,"产品"),
	Resource(4,"资源"),
	Mall(5,"商城"),
	Video(6,"视频"),
	Audio(7,"音频"),
	Guestbook(8,"留言"),
	Blog(9,"博客"),
	Forum(10,"论坛"),
	Community(11,"社圈");
	
	private Integer value;
	private String desc;
	/**
	 * 获取值
	 * @return
	 */
	public Integer getValue() {
		return value;
	}
	/**
	 * 设置值
	 * @param value
	 */
	public void setValue(Integer value) {
		this.value=value;
	}
	/**
	 * 获取描述
	 * @return
	 */
	public String getDesc() {
		return desc;
	}
	/**
	 * 设置描述
	 * @param desc
	 */
	public void setDesc(String desc) {
		this.desc=desc;
	}
	/**
	 * 初始化频道类型
	 * @param value
	 * @param desc
	 */
	private CatalogTypeDictionary(Integer value,String desc) {
		this.value=value;
		this.desc=desc;
	}
	
	/**
	 *根参数 取得类型
	 * @param value
	 * @return
	 */
	public static CatalogTypeDictionary getTypeByValue(Integer value) {
		CatalogTypeDictionary defaultType=CatalogTypeDictionary.Article;
		for(CatalogTypeDictionary catalogType:CatalogTypeDictionary.values()) {
			if(catalogType.value.equals(value)) {
				return catalogType;
			}
		}
		return defaultType;
	}
	
	/**
	 * 取得参数的类型描述
	 * @param value
	 * @return
	 */
	public static String getTypeByDesc(Integer value) {
		return getTypeByValue(value).desc;
	}

}
public @ResponseBody List<Map<String, String>>getCatalogType(){
		List<Map<String, String>>catalogList=new ArrayList<Map<String,String>>();
		for (CatalogTypeDictionary catalogType : CatalogTypeDictionary.values()) {
			Map<String, String>typeMap=new HashMap<String, String>();
			typeMap.put("typeName",catalogType.getDesc());
			typeMap.put("typeValue",catalogType.getValue());
			catalogList.add(typeMap);
		}
		return catalogList;
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值