快速开发之数据字典设计
在系统开发中,我们需要使用很多的类别、常用的下拉框等等静态数据,这些静态数据我们可以把它们写入到数据库的一张表中,通过这张表,我们维护它们之间的关系以及信息。
例如:性别、菜单项、下拉框常量等等静态数据
字段名称 | 数据类型 | 长度 | 约束 | 默认值 | 备注 |
id | int | 10 | pk | auto_increment | 主键字段 |
parent_id | int | 10 | null | 父类id,如果是父类,则为null | |
type | varchcar(128) | 128 | NN | 类型名称 | |
dict_code | varchar(128) | 128 | NN | 字典code值,使用因为或者数字 | |
dict_value | varchar(4000) | 4000 | NN | 字典Value值,英文或者中文 | |
order_value | int | 10 | 排序字段 |
MYSQL SQL脚本:
create table s_data_dict(
id int(10) primary key auto_increment,
parent_id int(10),
dict_type varchar(128) not null,
dict_code varchar(128) not null,
dict_value varchar(4000) not null,
order_value int(10)
)engine=innodb default charset utf8;
Oracle SQL脚本:
create table s_data_dict(
id number(10) primary key,
parent_id number(10),
dict_type varchar2(128) not null,
dict_code varchar2(128) not null,
dict_value varchar2(4000) not null,
order_value number(10)
);
实体类:
/**
*
* 类名称:DataDict
* 类描述:数据字典实体类
* 创建人:king-pan
* 修改时间:2014年12月25日
* @version 1.0
*
*/
public class DataDict implements Serializable {
private static final long serialVersionUID = 1677559039719764920L;
/**
* 主键字段
*/
private Integer id;
/**
* 父类ID
*/
private Integer parentId;
/**
* 类型
*/
private String type;
/**
* 字典code
*/
private String dictCode;
/**
* 字典值
*/
private String dictValue;
/**
* 排序字段
*/
private Integer orderValue;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getOrderValue() {
return orderValue;
}
public void setOrderValue(Integer orderValue) {
this.orderValue = orderValue;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDictCode() {
return dictCode;
}
public void setDictCode(String dictCode) {
this.dictCode = dictCode;
}
public String getDictValue() {
return dictValue;
}
public void setDictValue(String dictValue) {
this.dictValue = dictValue;
}
@Override
public String toString() {
return "DataDict [id=" + id + ", parentId=" + parentId + ", type="
+ type + ", dictCode=" + dictCode + ", dictValue=" + dictValue
+ ", orderValue=" + orderValue + "]";
}
}