字典表的设计

dict_codedict_parent_codedict_namedict_valuedisplay_order
BJ-1北京市  
BJ01BJ修正系数  
BJ011BJ01工业  
BJ012BJ01商业  
BJ0111BJ011工业用地1.5 

 

说明:

这种字典表的设计是为了存储树型结构,通过dict_code和dict_parent_code来存储父子关系。display_order可以有两种方式,一种是存储所有项的顺序,另一种方式是存储同级项的顺序。只有叶子才有dict_value值。

另外一个技巧就是dict_code的值,最好也存储了前缀形式,就是父项的dict_code一定是子项dict_code的前缀。01~0a~0A,也就是每一级可以有9+26+26=61个子项。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Java 中,可以使用 Map 接口来实现字典设计。Map 接口提供了 key-value 对的存储和访问方式,其中 key 字典中的关键字,value 示与关键字相关联的值。常用的 Map 实现类有 HashMap、TreeMap、LinkedHashMap 等。 下面是一个简单的例子,演示如何使用 HashMap 实现字典: ```java import java.util.HashMap; import java.util.Map; public class Dictionary { private Map<String, String> map; public Dictionary() { map = new HashMap<>(); } public void addEntry(String key, String value) { map.put(key, value); } public String getEntry(String key) { return map.get(key); } public void removeEntry(String key) { map.remove(key); } public boolean containsKey(String key) { return map.containsKey(key); } public static void main(String[] args) { Dictionary dict = new Dictionary(); dict.addEntry("apple", "a round fruit with red or green skin and a white inside"); dict.addEntry("banana", "a curved fruit with a yellow skin"); dict.addEntry("cherry", "a small, round fruit with a red or black skin and a hard seed inside"); System.out.println(dict.getEntry("apple")); System.out.println(dict.containsKey("pear")); dict.removeEntry("banana"); System.out.println(dict.containsKey("banana")); } } ``` 在上面的代码中,我们创建了一个 Dictionary 类,包含了 addEntry、getEntry、removeEntry 和 containsKey 等方法,分别用于添加、获取、删除和判断字典中是否包含某个关键字。在 main 方法中,我们向字典中添加了若干条词条,并测试了各种方法的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值