/** * 下拉选项返回模型对象 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; }
jsp下拉框展示枚举定义的信息,java下拉框定义枚举赋值
最新推荐文章于 2021-03-01 20:47:56 发布
本文介绍了一个简单的Java枚举类用于表示不同国家,并实现了一个方法来填充SelectBean对象列表,以便于在用户界面中显示为下拉框选项。
353

被折叠的 条评论
为什么被折叠?



