美文网首页
分库分表-shardingsphere+springboot+m

分库分表-shardingsphere+springboot+m

作者: dbasy | 来源:发表于2021-08-09 14:53 被阅读0次

    广播表 指所有的分片数据源中都存在的表,表结构和表中的数据在每个数据库中均完全一致。适用于数据量不 大且需要与海量数据的表进行关联查询的场景,例如:字典表。

    建立一张字段表

    image.png
    中间mapper层省略直接看结果
    @SpringBootTest
    public class ShardingBroadcastTests {
        @Autowired
        private DictMapper dictMapper;
    
        @Test
        public void insertDict() {
    
            Dict dict = new Dict().setDictName("first dict").setInsertDate(new Date());
            dictMapper.insert(dict);
    
        }
    
    
        @Test
        public void selectDict() {
    
    
            dictMapper.selectById(1L);
    
        }
    
    
    }
    
    

    插入将会插入到每个数据分片,查询只会从第一个数据分片进行查找

    相关文章

      网友评论

          本文标题:分库分表-shardingsphere+springboot+m

          本文链接:https://www.haomeiwen.com/subject/uvuzvltx.html