当前位置:网站首页>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);
}
边栏推荐
- [In-depth and easy-to-follow FPGA learning 15---------- Timing analysis basics]
- Jmeter参数传递方式(token传递,接口关联等)
- SWM32 Series Tutorial 6 - Systick and PWM
- background has no effect on child elements of float
- IOT跨平台组件设计方案
- The difference between substring and substr in MySQL
- binglog log tracking: data backup and backup tracking
- Basic usage of async functions and await expressions in ES6
- Shell programming of conditional statements
- How to import game archives in joiplay emulator
猜你喜欢
Detailed explanation of 9 common reasons for MySQL index failure
Restricted character bypass
正则表达式密码策略与正则回溯机制绕过
从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
[C language course design] C language campus card management system
程序员工作三年攒多少钱合适?
Mysql systemized JOIN operation example analysis
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
asser利用蚁剑登录
MySQL table design for message queue to store message data
随机推荐
ABC 261 F - Sorting Color Balls (reverse pair)
[Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
MySQL database advanced articles
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
Detailed explanation of 9 common reasons for MySQL index failure
正则表达式密码策略与正则回溯机制绕过
DOM系列之动画函数封装
What is Promise?What is the principle of Promise?How to use Promises?
【深入浅出玩转FPGA学习14----------测试用例设计2】
Preparations for web vulnerabilities
程序员工作三年攒多少钱合适?
【深度学习】Transformer模型详解
Summary of MySQL database interview questions (2022 latest version)
【多线程】
MySQL grant statements
MySQL数据库(基础)
Filter (Filter)
mysql索引失效的常见9种原因详解
Oracle一个诡异的临时表空间不足的问题
registers (assembly language)