标签:style omd snmp nbsp context engine font 字典 uid
CREATE TABLE `sys_dict`(
`id` INT(10) NOT NULL AUTO_INCREMENT COMMENT ‘主键id‘,
`dict_type` VARCHAR(50) NOT NULL DEFAULT ‘‘ COMMENT ‘字典类型‘,
`dict_key` INT(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘字典key‘,
`dict_value` VARCHAR(50) NOT NULL DEFAULT ‘‘ COMMENT ‘字典value‘,
`sort` INT(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘字典排序值‘,
`add_uid` INT(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘添加人‘,
`update_uid` INT(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘更新人‘,
`add_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘更新时间‘,
`del_flag` TINYINT(4) NOT NULL DEFAULT ‘0‘ COMMENT ‘删除标记‘,
`remark` VARCHAR(100) NOT NULL DEFAULT ‘‘ COMMENT ‘备注‘,
PRIMARY KEY (`id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT=‘数据字典表‘;
数据字典工具类
public class DictUtils {
private static SysDictMapper sysDictMapper = SpringContextUtils.getBeanByClass(SysDictMapper.class);
public static SysDictPo getDict(String dictType, Integer dictKey) {
SysDictPo sysDictPo = new SysDictPo();
sysDictPo.setDictType(dictType);
sysDictPo.setDictKey(dictKey);
return sysDictMapper.selectByTypeAndKey(sysDictPo);
}
public static String getDictValue(String dictType, Integer dictKey) {
SysDictPo query = getDict(dictType, dictKey);
if (query != null) {
return query.getDictValue();
}
return null;
}
}
数据字典的一个妙用是做一个开关
String value = DictUtils.getDictValue("switch",0);
Boolean switch = Boolean.valueOf(value);
if(switch){
//......
}else{
//.....
}
而dict_value我们可以通过接口修改,这样只需要修改数据库的值而不需改动代码
标签:style omd snmp nbsp context engine font 字典 uid
原文地址:http://www.cnblogs.com/winner-0715/p/5991651.html