springboot集成mbatisplus+sharding-jdbc+公共表

公共表的含义:

#公共表
#1.存储固定数据的表,表数据很少发生变化,查询时候经常关联
#2.每个数据库中创建相同结构公共表
#3.在多个数据库都创建相同结构公共表

 

CREATE TABLE udict(
dictid BIGINT(20) primary key comment '主键',
ustatus varchar(20) not null comment '名称',
uvalue VARCHAR(10) not null COMMENT '值');

 

配置文件:

spring.shardingsphere.sharding.binding-tables=udict
###公共表id生成策略
spring.shardingsphere.sharding.tables.udict.key-generator.column=dictid
spring.shardingsphere.sharding.tables.udict.key-generator.type=SNOWFLAKE
目前查询还不知道怎么查,,,
/**
*公共表
*/
@Data
public class Udict {
private Long dictid;
private String ustatus;
private String uvalue;
}

需要注意的是,由于是公共表,把每个库里的这个表都会插入一条sql,所以哦,必须每个库都要创建出来这个表哦。

 

/**
* @author player3
*/
@Repository
public interface UdictMapper extends BaseMapper<Udict> {

}


/**
* 单条插入
*/
@Test
public void addUdict() {
Udict udict = new Udict();
udict.setUstatus("1");
udict.setUvalue("dasdas");
udictMapper.insert(udict);
}

@Test
public void delUdict() {
QueryWrapper<Udict> wrapper = new QueryWrapper<>();
wrapper.eq("dictid",691789403802042369l);
udictMapper.delete(wrapper);

}
posted @ 2022-01-22 17:50  三号小玩家  阅读(78)  评论(0)    收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840