sharding-jdbc的逻辑表和实际表映射关系配置

Posted by KANG's BLOG on Tuesday, May 18, 2021

逻辑表和实际表映射关系配置

默认配置

TableRule orderTableRule = new TableRule("t_order", Arrays.asList("t_order_0", "t_order_1"), dataSourceRule);

自定义规则配置

TableRule orderTableRule = new TableRule("t_order", Arrays.asList("db0.t_order_0", "db0.t_order_1", "db1.t_order_2", "db1.t_order_3", "db1.t_order_4"), dataSourceRule);

例:

select * from t_order where user_id = ? and order_id = ?;

Sharding-JDBC将会将SQL语句转换为如下形式:

select * from db0.t_order_0 where user_id = ? and order_id = ?;