当前位置:网站首页>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数据库约束,表的设计
- 【Yugong Series】July 2022 Go Teaching Course 017-IF of Branch Structure
- 从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
- BOM系列之history对象
- MySQL的触发器
- 【深入浅出玩转FPGA学习13-----------测试用例设计1】
- [In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
- 小程序-全局数据共享
- Detailed explanation of 9 common reasons for MySQL index failure
- WMware Tools installation failed segmentation fault solution
猜你喜欢
Strict Mode for Databases
【Multithreading】
What is Promise?What is the principle of Promise?How to use Promises?
深度学习可以求解特定函数的参数么?
Xss target drone training [success when pop-up window is realized]
xss bypass: prompt(1)
ShardingSphere之垂直分库分表实战(五)
How to Add a Navigation Menu on Your WordPress Site
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
typescript17-函数可选参数
随机推荐
Thesis understanding: "Designing and training of a dual CNN for image denoising"
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
【952. 按公因数计算最大组件大小】
Summary of MySQL database interview questions (2022 latest version)
对象集合去重的方法
寄存器(汇编语言)
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
pytorch bilinear interpolation
DOM系列之scroll系列
【Yugong Series】July 2022 Go Teaching Course 019-For Circular Structure
MySQL grant statements
In-depth understanding of the auto-increment operator from two error-prone written test questions
typescript17 - function optional parameters
Shell programming of conditional statements
【深入浅出玩转FPGA学习15----------时序分析基础】
typescript15-(同时指定参数和返回值类型)
typescript17-函数可选参数
Jmeter参数传递方式(token传递,接口关联等)
[C language course design] C language campus card management system
【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers