您的位置:首页 > 编程语言 > Java开发

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

2016-12-14 15:59 323 查看
/**
* 下拉选项返回模型对象 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: