数据字典

1 篇文章 0 订阅
1 篇文章 0 订阅

在应用开发中,总会遇到许多数据字典项,比如对象状态、对象类型等等,这些项一般都是固定的若干可选值选项,比如对象状态可能有新建、修改、删除等状态,这些数据字典项一旦定义完毕改动的频率非常低在应用开发中,为了处理方便,一般要对这些数据字典项值选项进行数字编码(例如: 0表示新建,1表示修改,2表示删除等),以方便应用程序中使用。而UI显示对象信息时不能显示对象状态等的编码,对于编码值设计人员知道代表什么意思,但用户就不明白了,所以需要进行编码转换,从编码转换为文字描述(名称),也就是需要把状态编码0转换为“新建”,把1转换为“修改”,把2转换为“删除”等显示给用户,用户才明白对象当前的状态是什么。

具体实现

这里写图片描述

1、关系数据库

首先要创建实体对象表和数据字典表
其中实体对象表中的数据字典项为数据字典表的主键。
这里写图片描述

2、 实体对象

Customer

public class Customer {


    private Long cust_id;

    private String cust_name;
    //使用数据字典对象代替
    //private String cust_source;
    //private String cust_industry;
    //private String cust_level;
    private String cust_linkman;
    private String cust_phone;
    private String cust_mobile;

    //引用关联的数据字典对象
    private BaseDict cust_source; //客户来源 cust_source.dict_id
    private BaseDict cust_industry; //客户行业
    private BaseDict cust_level; //客户级别

    ......

BaseDict

public class BaseDict {

    private String dict_id;
    private String dict_type_code;
    private String dict_type_name;
    private String dict_item_name;
    private String dict_item_code;
    private String dict_memo;
    private Integer dict_sort;
    private Character dict_enable;

    ......

3、 配置文件

customer.hbm.xml

<hibernate-mapping package="cn.itcast.domain" >
    <class name="Customer" table="cst_customer" >
        <id name="cust_id"  >
            <generator class="native"></generator>
        </id>
        <property name="cust_name" column="cust_name" ></property>
        <!-- 使用数据字典对象代替 -->
        <!-- <property name="cust_source" column="cust_source" ></property>
        <property name="cust_industry" column="cust_industry" ></property>
        <property name="cust_level" column="cust_level" ></property> -->
        <property name="cust_linkman" column="cust_linkman" ></property>
        <property name="cust_phone" column="cust_phone" ></property>
        <property name="cust_mobile" column="cust_mobile" ></property>

        <!-- 多对一 -->
        <many-to-one name="cust_source" column="cust_source" class="BaseDict" ></many-to-one>
        <many-to-one name="cust_industry" column="cust_industry" class="BaseDict" ></many-to-one>
        <many-to-one name="cust_level" column="cust_level" class="BaseDict" ></many-to-one>
    </class>
</hibernate-mapping>

baseDict.hbm.xml

<hibernate-mapping package="cn.itcast.domain" >
    <class name="BaseDict" table="base_dict" >
        <id name="dict_id"  >
            <generator class="assigned"></generator>
        </id>
        <property name="dict_type_code" ></property>
        <property name="dict_type_name" ></property>
        <property name="dict_item_name" ></property>
        <property name="dict_item_code" ></property>
        <property name="dict_memo" ></property>
        <property name="dict_sort" ></property>
        <property name="dict_enable" ></property>
    </class>
</hibernate-mapping>
                    技术交流:713788313
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值