总结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>
阅读全文
0 0
- 总结2-字典表的使用
- 自定义字典表的使用
- 字典类表的建立和使用
- python学习笔记2-字典的使用
- 数据库-字典的使用
- 字典树的使用
- Swift字典的使用
- 字典的使用
- NSDictionary字典的使用
- 字典的使用
- Python 字典的使用
- 字典的使用
- ICTCLAS 字典保存的总结
- 关于数据字典的使用
- python 字典dict 的使用
- 使用数据字典的实例
- JEECG-数据字典的使用
- Dictionary字典类型的使用
- html5调用摄像头实现拍照
- 计算机网络:隐式拥塞控制综述
- Struct2运行原理与机制
- 如何用JS刷新当前页面
- JAVA File解析
- 总结2-字典表的使用
- php将base64编码转换为图片保存至指定位置
- Leetcode(17)
- Linux内核源码--min,swap宏定义
- shell变量
- 转:对自动化测试的理解
- Struts2 OGNL
- Android Studio 小技巧
- 从国企到阿里的面试经历(二)