字典表设计

CREATE TABLE `dic` (
  `id` bigint(32) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL COMMENT '字典描述名',
  `description` varchar(255) DEFAULT NULL COMMENT '字典描述',
  `dic_key` varchar(255) DEFAULT NULL COMMENT '字典key(惟一标识)',
  `system_code` varchar(255) DEFAULT NULL COMMENT '字典类型码',
  `delete_flag` int(2) DEFAULT '0' COMMENT '0=未删除,1= 已删除, 0为有效(default)',
  `create_user_id` varchar(32) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_user_id` varchar(32) DEFAULT NULL,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `struct` varchar(255) DEFAULT NULL COMMENT '结构层级',
  `flag` int(10) DEFAULT '0' COMMENT '是否可配置,0-可配置 1-不可配置',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;


CREATE TABLE `dic_item` (
  `id` bigint(32) NOT NULL AUTO_INCREMENT,
  `dic_item_key` varchar(255) DEFAULT NULL COMMENT '字典数据KEY',
  `dic_item_value` varchar(255) DEFAULT NULL COMMENT '字典数据value',
  `comment` varchar(255) DEFAULT NULL COMMENT '备注',
  `dic_key` varchar(255) DEFAULT NULL COMMENT '字典key(惟一标识)',
  `delete_flag` int(2) DEFAULT '0' COMMENT '0=未删除,1= 已删除, 0为有效(default)',
  `create_user_id` varchar(32) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_user_id` varchar(32) DEFAULT NULL,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `code` varchar(255) DEFAULT NULL COMMENT 'code码',
  `parent_code` varchar(255) DEFAULT NULL COMMENT '父code码',
  `levels` int(10) DEFAULT '1' COMMENT '等级',
  `rent_tenant_id` varchar(50) DEFAULT NULL COMMENT '租赁公司租户id',
  `enterprise_tenant_id` varchar(50) DEFAULT NULL COMMENT '资产管理公司租户id',
  PRIMARY KEY (`id`),
  UNIQUE KEY `enterid_dicitemvalue` (`dic_item_value`,`enterprise_tenant_id`,`dic_key`)
) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8;

在 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、付费专栏及课程。

余额充值