jsp下拉框展示枚举定义的信息,java下拉框定义枚举赋值

本文介绍了一个简单的Java枚举类用于表示不同国家,并实现了一个方法来填充SelectBean对象列表,以便于在用户界面中显示为下拉框选项。
/**
 * 下拉选项返回模型对象 created by tely on 2015/06/15.
 */
@Data
public class SelectBean implements Serializable {
   private String key;
   private String value;

   private List<SelectBean> subObj;

}
package com.ig.sid.syssetting.util;

/**
 * 国家枚举类
 * Created by tely on 2015/8/13.
 */
public enum CountryEnum {

    COUNTRY_ENUM_CN("enum_country_cn","CN"),//中国
    COUNTRY_ENUM_VN("enum_country_vn","VN"),//越南
    COUNTRY_ENUM_TH("enum_country_th","TH"),//泰国
    COUNTRY_ENUM_ID("enum_country_id","ID"),//印度尼西亚
    COUNTRY_ENUM_JP("enum_country_jp","JP"),//日本
    COUNTRY_ENUM_KH("enum_country_kh","KH"),//柬埔寨
    COUNTRY_ENUM_KP("enum_country_kp","KP");//韩国


    private String nameKey;

    private String code;

    public String getNameKey(){
       return this.nameKey;
    }

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

    //构造函数必须为private,防止意外调用
    private CountryEnum(String nameKey, String code){
        this.nameKey = nameKey;
        this.code = code;
    }
}
/**
 * 查找所有国家填充下拉框
 * @return list
 */
@RequestMapping("findCountryFillSelect")
@ResponseBody
public List<SelectBean> findCountryFillSelect(HttpSession session) {
    List<SelectBean> list = new ArrayList<SelectBean>();
    try{
        SelectBean bean ;
        for(CountryEnum e: CountryEnum.values()){
            bean = new SelectBean();
            bean.setKey(e.getCode());
            bean.setValue(e.getNameKey());
            list.add(bean);
        }
    }catch (Exception e) {
        logger.error(e.getMessage());
    }
    return list;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值