当前位置:网站首页>ShardingSphere's public table combat (7)
ShardingSphere's public table combat (7)
2022-07-31 00:48:00 【Rongji】
概述
场景
- What is a common table?
存储固定数据的表,The data in the table is seldom change,查询时经常进行关联,比如字典表. - Each database to create the same structure of common table.
SpringBoot环境搭建
建表
In multiple databases are created the same common table structure.
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);
}
边栏推荐
猜你喜欢

mysql索引失效的常见9种原因详解

Error in go mode tidy go warning “all” matched no packages

Mysql systemized JOIN operation example analysis

Jmeter参数传递方式(token传递,接口关联等)

程序员工作三年攒多少钱合适?

【多线程】

MySQL table design for message queue to store message data

Niuke.com question brushing training (4)

MySQL database advanced articles

【952. 按公因数计算最大组件大小】
随机推荐
MySQL数据库面试题总结(2022最新版)
Xss target drone training [success when pop-up window is realized]
Filter (Filter)
The difference between truncate and delete in MySQL database
Optimization of aggregate mentioned at DATA AI Summit 2022
不用Swagger,那我用啥?
h264和h265解码上的区别
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
typescript12-联合类型
WMware Tools安装失败segmentation fault解决方法
BOM系列之Navigator对象
TypeScript在使用中出现的问题记录
MySQL的触发器
xss bypass: prompt(1)
XSS related knowledge
ShardingSphere之读写分离(八)
SWM32 Series Tutorial 6 - Systick and PWM
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
Gabor滤波器学习笔记
【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符