当前位置:网站首页>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);
}
边栏推荐
- Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
- BOM系列之Navigator对象
- Go 学习笔记(84)— Go 项目目录结构
- 【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers
- 不用Swagger,那我用啥?
- In-depth understanding of the auto-increment operator from two error-prone written test questions
- Regular expression password policy and regular backtracking mechanism bypass
- redis学习
- 过滤器(Filter)
- mysql主从复制及读写分离脚本-亲测可用
猜你喜欢

Error occurred while trying to proxy request项目突然起不来了

MySQL database advanced articles

从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术

Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv

Strict Mode for Databases

mysql主从复制及读写分离脚本-亲测可用

不用Swagger,那我用啥?

神经网络(ANN)

The difference between h264 and h265 decoding

WEB Security Basics - - - Vulnerability Scanner
随机推荐
SereTOD2022 Track2代码剖析-面向半监督和强化学习的任务型对话系统挑战赛
Mini Program - Global Data Sharing
Go 学习笔记(84)— Go 项目目录结构
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
这个项目太有极客范儿了
GO GOPROXY proxy Settings
MySQL筑基篇之增删改查
BOM系列之history对象
The client series of the DOM series
binglog log tracking: data backup and backup tracking
IOT跨平台组件设计方案
【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers
华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘
【多线程】
unity2D横版游戏教程4-物品收集以及物理材质
ShardingSphere之未分片表配置实战(六)
SWM32 Series Tutorial 6 - Systick and PWM
MySQL笔记下
MySQL系列一:账号管理与引擎
Jetpack Compose learning (8) - State and remeber