当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

会议OA项目待开会议、所有会议功能

h264和h265解码上的区别

Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a

Shell编程之条件语句

MySQL的触发器

Mini Program - Global Data Sharing

(五)fastai应用

Neural Network (ANN)
![[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]](/img/c0/1130111c90b1bc175b088894c1c18f.png)
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]

程序员工作三年攒多少钱合适?
随机推荐
MySQL master-slave replication and read-write separation script - pro test available
论文理解:“Designing and training of a dual CNN for image denoising“
Kotlin协程:协程上下文与上下文元素
xss bypass: prompt(1)
MySQL数据库的truncate与delete区别
ABC 261 F - Sorting Color Balls (reverse pair)
【Demo】ABAP Base64加解密测试
【c语言课程设计】C语言校园卡管理系统
作业:iptables防止nmap扫描以及binlog
【Yugong Series】July 2022 Go Teaching Course 019-For Circular Structure
[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
Jmeter parameter transfer method (token transfer, interface association, etc.)
GO GOPROXY proxy Settings
Neural Network (ANN)
MySQL grant statements
MySQL中substring与substr区别
消息队列存储消息数据的MySQL表设计
【唐宇迪 深度学习-3D点云实战系列】学习笔记
【愚公系列】2022年07月 Go教学课程 017-分支结构之IF
WEB安全基础 - - -漏洞扫描器