From 0be58dbf7774fef98ddac83c3f454b49c6d5a6c1 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 07 七月 2023 18:18:26 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java index dbac4e9..79c5c4c 100644 --- a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java +++ b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java @@ -68,20 +68,21 @@ //分片规则配置 ShardingRuleConfiguration result1 = new ShardingRuleConfiguration(); - result1.getTables().add(gettCoursePackagePaymentTableRuleConfiguration()); + result1.getTables().add(getCoursePackagePaymentTableRuleConfiguration()); Properties props1 = new Properties(); props1.setProperty("algorithm-expression", "t_course_package_payment$->{appUserId % 5 + 1}"); result1.getShardingAlgorithms().put("t_course_package_payment-inline", new AlgorithmConfiguration("INLINE", props1)); result1.getKeyGenerators().put("t_course_package_payment-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); + linkedList.add(result1); //分片规则配置 - result1.getTables().add(getCoursePackageStudentTableRuleConfiguration()); + ShardingRuleConfiguration result2 = new ShardingRuleConfiguration(); + result2.getTables().add(getCoursePackageStudentTableRuleConfiguration()); Properties props2 = new Properties(); props2.setProperty("algorithm-expression", "t_course_package_student$->{appUserId % 5 + 1}"); - result1.getShardingAlgorithms().put("t_course_package_student-inline", new AlgorithmConfiguration("INLINE", props2)); - result1.getKeyGenerators().put("t_course_package_student-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); - - linkedList.add(result1); + result2.getShardingAlgorithms().put("t_course_package_student-inline", new AlgorithmConfiguration("INLINE", props2)); + result2.getKeyGenerators().put("t_course_package_student-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); + linkedList.add(result2); return linkedList; } @@ -90,8 +91,8 @@ * 分片算法配置 * @return */ - private ShardingTableRuleConfiguration gettCoursePackagePaymentTableRuleConfiguration() { - ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m$->{0}.t_course_package_payment$->{1..5}");//50 + private ShardingTableRuleConfiguration getCoursePackagePaymentTableRuleConfiguration() { + ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m_$->{0}.t_course_package_payment$->{1..5}");//50 result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_payment-inline")); result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_payment-snowflake")); return result; @@ -104,7 +105,7 @@ * @return */ private ShardingTableRuleConfiguration getCoursePackageStudentTableRuleConfiguration() { - ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_student", "m$->{0}.t_course_package_student$->{1..5}");//30 + ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_student", "m_$->{0}.t_course_package_student$->{1..5}");//30 result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_student-inline")); result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_student-snowflake")); return result; -- Gitblit v1.7.1