总结2-字典表的使用

来源:互联网 发布:windows server 2008 编辑:程序博客网 时间:2024/04/29 09:28

使用方式
1. 取到下拉框的枚举标签
2. 将卡券表中取到的枚举值转化为标签。
这里写图片描述
修改为:
这里写图片描述
9行代码改成一行了呢。
传入参数:
枚举类型,字典类型,默认值为空

1. 如果枚举类型或者字典类型为空,返回默认值
2. 否则查找字典缓存
如果缓存为空,查找所有的字段值放入缓存。
3. 返回标签值

    @Transactional    @Override    public String getDictLabel(String value, String type, String defaultValue){        if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(value)){            for (Dict dict : getDictList(type)){                if (type.equals(dict.getType()) && value.equals(dict.getValue())){                    return dict.getLabel();                }            }        }        return defaultValue;    }    @Transactional    @Override    public  List<Dict> getDictList(String type){        @SuppressWarnings("unchecked")        Map<String, List<Dict>> dictMap = (Map<String, List<Dict>>) CacheUtils.get(CacheConstant.CACHE_DICT_MAP);        if (dictMap==null){            dictMap = Maps.newHashMap();            for (Dict dict : dao.findAllList(new Dict())){                List<Dict> dictList = dictMap.get(dict.getType());                if (dictList != null){                    dictList.add(dict);                }else{                    dictMap.put(dict.getType(), Lists.newArrayList(dict));                }            }//          CacheUtils.put(CacheConstant.CACHE_DICT_MAP, dictMap);        }        List<Dict> dictList = dictMap.get(type);        if (dictList == null){            dictList = Lists.newArrayList();        }        return dictList;    }
    <select id="findAllList" resultType="Dict">        SELECT             *         FROM td_sys_dict         WHERE del_flag = #{DEL_FLAG_NORMAL}         ORDER BY type, sort, update_date DESC    </select>