当前位置:网站首页>ShardingSphere之公共表实战(七)
ShardingSphere之公共表实战(七)
2022-07-31 00:40:00 【融极】
概述
场景
- 什么叫公共表?
存储固定数据的表,表中的数据很少发生变化,查询时经常进行关联,比如字典表。 - 每个数据库中创建出相同结构的公共表。
SpringBoot环境搭建
建表
在多个数据库中都创建结构相同的公共表。
CREATE TABLE `t_udict` (
`dictid` BIGINT(11) NOT NULL PRIMARY KEY,
`ustatus` varchar(255) DEFAULT NULL,
`uvalue` varchar(255) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
application.properties配置
# 配置公共表
spring.shardingsphere.sharding.broadcast-tables=t_udict
spring.shardingsphere.sharding.tables.t_udict.key-generator.column=dictid
spring.shardingsphere.sharding.tables.t_udict.key-generator.type=SNOWFLAKE
编写代码
package com.study.shardingjdbcdemo.entity;
import lombok.Data;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Table(name = "t_udict")
public class Udict {
@Id
private Long dictid;
private String ustatus;
private String uvalue;
}
package com.study.shardingjdbcdemo.mapper;
import com.study.shardingjdbcdemo.entity.Udict;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
@Repository
public interface UdictMapper extends Mapper<Udict> {
}
测试代码
@Test
public void addCommon() {
Udict udict = new Udict();
udict.setUvalue("已启用");
udict.setUstatus("a");
udictMapper.insertSelective(udict);
}
@Test
public void deleteCommon() {
udictMapper.deleteByPrimaryKey(760236497562501121l);
}
边栏推荐
- 【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers
- MySQL的grant语句
- 消息队列存储消息数据的MySQL表设计
- SereTOD2022 Track2代码剖析-面向半监督和强化学习的任务型对话系统挑战赛
- ES6中 async 函数、await表达式 的基本用法
- Linux 部署mysql 5.7全程跟踪 完整步骤 django部署
- binglog日志追踪:数据备份并备份追踪
- 【深入浅出玩转FPGA学习15----------时序分析基础】
- 作业:iptables防止nmap扫描以及binlog
- How to import game archives in joiplay emulator
猜你喜欢
随机推荐
Method for deduplication of object collection
【c语言课程设计】C语言校园卡管理系统
Encapsulate and obtain system user information, roles and permission control
How to solve the error of joiplay simulator
【愚公系列】2022年07月 Go教学课程 013-常量、指针
DATA AI Summit 2022提及到的对 aggregate 的优化
Restricted character bypass
过滤器(Filter)
Preparations for web vulnerabilities
[Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
MySQL Series 1: Account Management and Engine
binglog log tracking: data backup and backup tracking
会议OA项目待开会议、所有会议功能
Mysql体系化之JOIN运算实例分析
Go 学习笔记(84)— Go 项目目录结构
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
场景之多数据源查询及数据下载问题
MySQL数据库进阶篇
Gabor滤波器学习笔记
MySQL database (basic)