当前位置:网站首页>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);
}
边栏推荐
- 从两个易错的笔试题深入理解自增运算符
- [Deep learning] Detailed explanation of Transformer model
- WMware Tools installation failed segmentation fault solution
- ABC 261 F - Sorting Color Balls (reverse pair)
- Regular expression password policy and regular backtracking mechanism bypass
- DOM系列之 offset 系列
- The client series of the DOM series
- background has no effect on child elements of float
- MySQL table design for message queue to store message data
- Redis learning
猜你喜欢
Asser uses ant sword to log in
场景之多数据源查询及数据下载问题
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
typescript17 - function optional parameters
MySQL table design for message queue to store message data
小程序-全局数据共享
Thesis understanding: "Designing and training of a dual CNN for image denoising"
h264和h265解码上的区别
MySQL master-slave replication and read-write separation script - pro test available
[C language course design] C language campus card management system
随机推荐
pytorch bilinear interpolation
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
[Deep learning] Detailed explanation of Transformer model
unity2D横版游戏教程4-物品收集以及物理材质
typescript14-(单独指定参数和返回值的类型)
MySQL database advanced articles
C语言力扣第48题之旋转图像。辅助数组
Jetpack Compose learning (8) - State and remeber
ELK deployment script---pro test available
WMware Tools installation failed segmentation fault solution
Asser uses ant sword to log in
C language force buckles the rotating image of the 48th question.auxiliary array
什么是Promise?Promise的原理是什么?Promise怎么用?
Adding, deleting, modifying and checking the foundation of MySQL
MySQL master-slave replication and read-write separation script - pro test available
ShardingSphere之垂直分库分表实战(五)
【ABAP】MFBF过账到质量检验库存类型Demo
DOM系列之动画函数封装
[Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
redis学习