diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index cf45691e..a4088d50 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -492,3 +492,16 @@ services: - /docker/grafana/grafana.ini:/etc/grafana/grafana.ini - /docker/grafana:/var/lib/grafana network_mode: "host" + shardingproxy: + image: apache/shardingsphere-proxy + container_name: shardingsphere-proxy + restart: always + command: server /data + ports: + - 13307:3307 + volumes: + - /docker/shardingproxy/conf:/opt/shardingsphere-proxy/conf + - /docker/shardingproxy/ext-lib:/opt/shardingsphere-proxy/ext-lib + environment: + - JVM_OPTS="-Djava.awt.headless=true" + network_mode: "host" diff --git a/docker/shardingproxy/conf/config-database-discovery.yaml b/docker/shardingproxy/conf/config-database-discovery.yaml new file mode 100644 index 00000000..a8c2bd15 --- /dev/null +++ b/docker/shardingproxy/conf/config-database-discovery.yaml @@ -0,0 +1,125 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +###################################################################################################### +# +# Here you can configure the rules for the proxy. +# This example is configuration of HA rule. +# +###################################################################################################### +# +#schemaName: database_discovery_db +# +#dataSources: +# primary_ds: +# url: jdbc:postgresql://127.0.0.1:5432/demo_primary_ds +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# replica_ds_0: +# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# replica_ds_1: +# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !DB_DISCOVERY +# dataSources: +# pr_ds: +# dataSourceNames: +# - ds_0 +# - ds_1 +# - ds_2 +# discoveryTypeName: mgr +# discoveryTypes: +# mgr: +# type: MGR +# props: +# groupName: 92504d5b-6dec-11e8-91ea-246e9612aaf1 +# zkServerLists: 'localhost:2181' +# keepAliveCron: '0/5 * * * * ?' + +###################################################################################################### +# +# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. +# +###################################################################################################### + +#schemaName: database_discovery_db +# +#dataSources: +# ds_0: +# url: jdbc:mysql://127.0.0.1:3306/demo_primary_ds?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# ds_1: +# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# ds_2: +# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 3000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !DB_DISCOVERY +# dataSources: +# pr_ds: +# dataSourceNames: +# - ds_0 +# - ds_1 +# - ds_2 +# discoveryTypeName: mgr +# discoveryTypes: +# mgr: +# type: MGR +# props: +# groupName: 92504d5b-6dec-11e8-91ea-246e9612aaf1 +# zkServerLists: 'localhost:2181' +# keepAliveCron: '0/5 * * * * ?' diff --git a/docker/shardingproxy/conf/config-encrypt.yaml b/docker/shardingproxy/conf/config-encrypt.yaml new file mode 100644 index 00000000..6c27d75f --- /dev/null +++ b/docker/shardingproxy/conf/config-encrypt.yaml @@ -0,0 +1,113 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +###################################################################################################### +# +# Here you can configure the rules for the proxy. +# This example is configuration of encrypt rule. +# +###################################################################################################### +# +#schemaName: encrypt_db +# +#dataSources: +# ds_0: +# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_0 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# ds_1: +# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_1 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !ENCRYPT +# encryptors: +# aes_encryptor: +# type: AES +# props: +# aes-key-value: 123456abc +# md5_encryptor: +# type: MD5 +# tables: +# t_encrypt: +# columns: +# user_id: +# plainColumn: user_plain +# cipherColumn: user_cipher +# encryptorName: aes_encryptor +# order_id: +# cipherColumn: order_encrypt +# encryptorName: md5_encryptor + +###################################################################################################### +# +# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. +# +###################################################################################################### +# +#schemaName: encrypt_db +# +#dataSources: +# ds_0: +# url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# ds_1: +# url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !ENCRYPT +# encryptors: +# aes_encryptor: +# type: AES +# props: +# aes-key-value: 123456abc +# md5_encryptor: +# type: MD5 +# tables: +# t_encrypt: +# columns: +# user_id: +# plainColumn: user_plain +# cipherColumn: user_cipher +# encryptorName: aes_encryptor +# order_id: +# cipherColumn: order_cipher +# encryptorName: md5_encryptor diff --git a/docker/shardingproxy/conf/config-readwrite-splitting.yaml b/docker/shardingproxy/conf/config-readwrite-splitting.yaml new file mode 100644 index 00000000..e8bd395e --- /dev/null +++ b/docker/shardingproxy/conf/config-readwrite-splitting.yaml @@ -0,0 +1,109 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +###################################################################################################### +# +# Here you can configure the rules for the proxy. +# This example is configuration of replica-query rule. +# +###################################################################################################### +# +#schemaName: readwrite_splitting_db +# +#dataSources: +# primary_ds: +# url: jdbc:postgresql://127.0.0.1:5432/demo_primary_ds +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# replica_ds_0: +# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# replica_ds_1: +# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !READWRITE_SPLITTING +# dataSources: +# pr_ds: +# writeDataSourceName: primary_ds +# readDataSourceNames: +# - replica_ds_0 +# - replica_ds_1 + +###################################################################################################### +# +# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. +# +###################################################################################################### + +#schemaName: readwrite_splitting_db +# +#dataSources: +# write_ds: +# url: jdbc:mysql://127.0.0.1:3306/demo_write_ds?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# read_ds_0: +# url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# read_ds_1: +# url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !READWRITE_SPLITTING +# dataSources: +# pr_ds: +# writeDataSourceName: write_ds +# readDataSourceNames: +# - read_ds_0 +# - read_ds_1 diff --git a/docker/shardingproxy/conf/config-shadow.yaml b/docker/shardingproxy/conf/config-shadow.yaml new file mode 100644 index 00000000..6831ab5a --- /dev/null +++ b/docker/shardingproxy/conf/config-shadow.yaml @@ -0,0 +1,179 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +###################################################################################################### +# +# Here you can configure the rules for the proxy. +# This example is configuration of shadow rule. +# +###################################################################################################### +# +#schemaName: shadow_db +# +#dataSources: +# ds: +# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_0 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# shadow_ds: +# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_1 +# username: postgres +# password: postgres +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !SHADOW +# enable: true +# dataSources: +# shadowDataSource: +# sourceDataSourceName: ds +# shadowDataSourceName: shadow_ds +# tables: +# t_order: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-select-match-algorithm +# t_order_item: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-update-match-algorithm +# - user-id-select-match-algorithm +# t_address: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-select-match-algorithm +# - simple-note-algorithm +# shadowAlgorithms: +# user-id-insert-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: insert +# column: user_id +# regex: "[1]" +# user-id-update-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: update +# column: user_id +# regex: "[1]" +# user-id-select-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: select +# column: user_id +# regex: "[1]" +# simple-note-algorithm: +# type: SIMPLE_NOTE +# props: +# shadow: true +# foo: bar + +###################################################################################################### +# +# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory. +# +###################################################################################################### +# +#schemaName: shadow_db +# +#dataSources: +# ds: +# url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# shadow_ds: +# url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# +#rules: +#- !SHADOW +# enable: true +# dataSources: +# shadowDataSource: +# sourceDataSourceName: ds +# shadowDataSourceName: shadow_ds +# tables: +# t_order: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-select-match-algorithm +# t_order_item: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-update-match-algorithm +# - user-id-select-match-algorithm +# t_address: +# dataSourceNames: +# - shadowDataSource +# shadowAlgorithmNames: +# - user-id-insert-match-algorithm +# - user-id-select-match-algorithm +# - simple-note-algorithm +# shadowAlgorithms: +# user-id-insert-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: insert +# column: user_id +# regex: "[1]" +# user-id-update-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: update +# column: user_id +# regex: "[1]" +# user-id-select-match-algorithm: +# type: COLUMN_REGEX_MATCH +# props: +# operation: select +# column: user_id +# regex: "[1]" +# simple-note-algorithm: +# type: SIMPLE_NOTE +# props: +# shadow: true +# foo: bar diff --git a/docker/shardingproxy/conf/config-sharding.yaml b/docker/shardingproxy/conf/config-sharding.yaml new file mode 100644 index 00000000..4b8e5be3 --- /dev/null +++ b/docker/shardingproxy/conf/config-sharding.yaml @@ -0,0 +1,84 @@ +###################################################################################################### +# +# 用于配置:数据分片规则 +# +###################################################################################################### + +schemaName: data-center_db + +dataSources: + ds_0: + url: jdbc:mysql://192.168.0.60:3306/data-center_0?serverTimezone=UTC&useSSL=false + username: root + password: root + connectionTimeoutMilliseconds: 30000 + idleTimeoutMilliseconds: 60000 + maxLifetimeMilliseconds: 1800000 + maxPoolSize: 50 + minPoolSize: 1 + ds_1: + url: jdbc:mysql://192.168.0.60:3306/data-center_1?serverTimezone=UTC&useSSL=false + username: root + password: root + connectionTimeoutMilliseconds: 30000 + idleTimeoutMilliseconds: 60000 + maxLifetimeMilliseconds: 1800000 + maxPoolSize: 50 + minPoolSize: 1 + +rules: + - !SHARDING + tables: # 数据分片规则配置 + t_order: # 订单逻辑表名称 + actualDataNodes: ds_${0..1}.t_order_${0..1} + databaseStrategy: # 配置分库策略 + standard: + shardingColumn: user_id + shardingAlgorithmName: database_user_inline + tableStrategy: # 分表策略 + standard: + shardingColumn: order_id + shardingAlgorithmName: t_order_inline + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + t_order_item: # 子订单逻辑表名称 + actualDataNodes: ds_${0..1}.t_order_item_${0..1} + databaseStrategy: # 配置分库策略 + standard: + shardingColumn: user_id + shardingAlgorithmName: database_user_inline + tableStrategy: # 分表策略 + standard: + shardingColumn: order_id + shardingAlgorithmName: t_order_item_inline + keyGenerateStrategy: + column: order_item_id + keyGeneratorName: snowflake + bindingTables: # 绑定表规则列表 + - t_order,t_order_item + + # 分片算法配置 + shardingAlgorithms: + database_user_inline: + type: INLINE + props: + algorithm-expression: ds_${user_id % 2} + t_order_inline: # 订单表分片算法名称 + type: INLINE + props: + algorithm-expression: t_order_${order_id % 2} + allow-range-query-with-inline-sharding: true + t_order_item_inline: # 子订单表分片算法名称 + type: INLINE + props: + algorithm-expression: t_order_item_${order_id % 2} + allow-range-query-with-inline-sharding: true + + # 分布式序列算法配置 + keyGenerators: + snowflake: + type: SNOWFLAKE + props: + worker-id: 1 + diff --git a/docker/shardingproxy/conf/logback.xml b/docker/shardingproxy/conf/logback.xml new file mode 100644 index 00000000..fad52088 --- /dev/null +++ b/docker/shardingproxy/conf/logback.xml @@ -0,0 +1,45 @@ + + + + + + + [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/shardingproxy/conf/server.yaml b/docker/shardingproxy/conf/server.yaml new file mode 100644 index 00000000..9afbb08e --- /dev/null +++ b/docker/shardingproxy/conf/server.yaml @@ -0,0 +1,61 @@ +###################################################################################################### +# +# 用于配置:数据接入迁移&弹性伸缩、分布式治理模式、权限、代理属性. +# +###################################################################################################### + +#scaling: +# blockQueueSize: 10000 # 数据传输通道队列大小 +# workerThread: 40 # 工作线程池大小,允许同时运行的迁移任务线程数 +# clusterAutoSwitchAlgorithm: +# type: IDLE +# props: +# incremental-task-idle-minute-threshold: 30 +# dataConsistencyCheckAlgorithm: +# type: DEFAULT +# +#mode: +# type: Cluster +# repository: +# type: ZooKeeper +# props: +# namespace: governance_ds +# server-lists: localhost:2181 +# retryIntervalMilliseconds: 500 +# timeToLiveSeconds: 60 +# maxRetries: 3 +# operationTimeoutMilliseconds: 500 +# overwrite: false +# +rules: + - !AUTHORITY + users: + - root@%:root + - sharding@:sharding + provider: + type: ALL_PRIVILEGES_PERMITTED + - !TRANSACTION + defaultType: XA + providerType: Atomikos + +props: + max-connections-size-per-query: 1 + kernel-executor-size: 16 # Infinite by default. + proxy-frontend-flush-threshold: 128 # The default value is 128. + # proxy-opentracing-enabled: false + # proxy-hint-enabled: false + sql-show: true + # check-table-metadata-enabled: false + # show-process-list-enabled: false + # # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy. + # # The default value is -1, which means set the minimum value for different JDBC drivers. + # proxy-backend-query-fetch-size: -1 + check-duplicate-table-enabled: true +# sql-comment-parse-enabled: false +# proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide. +# # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution +# # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL. +# proxy-backend-executor-suitable: OLAP +# proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation. +# sql-federation-enabled: false + diff --git a/docker/shardingproxy/ext-lib/mysql-connector-java-8.0.11.jar b/docker/shardingproxy/ext-lib/mysql-connector-java-8.0.11.jar new file mode 100644 index 00000000..c3b5f703 Binary files /dev/null and b/docker/shardingproxy/ext-lib/mysql-connector-java-8.0.11.jar differ diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrder.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrder.java new file mode 100644 index 00000000..5137f846 --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrder.java @@ -0,0 +1,16 @@ +package org.dromara.demo.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@TableName("t_order") +@Data +public class TOrder { + + + private Long orderId; + + private Long userId; + + private int totalMoney; +} diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrderItem.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrderItem.java new file mode 100644 index 00000000..1b176491 --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/domain/TOrderItem.java @@ -0,0 +1,17 @@ +package org.dromara.demo.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@TableName("t_order_item") +@Data +public class TOrderItem { + + private Long orderItemId; + + private Long orderId; + + private Long userId; + + private int totalMoney; +} diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderItemMapper.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderItemMapper.java new file mode 100644 index 00000000..a158a19a --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderItemMapper.java @@ -0,0 +1,12 @@ +package org.dromara.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import org.apache.ibatis.annotations.Mapper; +import org.dromara.demo.domain.TOrderItem; + +@Mapper +public interface TOrderItemMapper extends BaseMapper { + + +} diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderMapper.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderMapper.java new file mode 100644 index 00000000..a65d1fc9 --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/mapper/TOrderMapper.java @@ -0,0 +1,12 @@ +package org.dromara.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import org.apache.ibatis.annotations.Mapper; +import org.dromara.demo.domain.TOrder; + +@Mapper +public interface TOrderMapper extends BaseMapper { + + +} diff --git a/ruoyi-example/ruoyi-demo/src/main/resources/application.yml b/ruoyi-example/ruoyi-demo/src/main/resources/application.yml index fe35e428..2e8e81b4 100644 --- a/ruoyi-example/ruoyi-demo/src/main/resources/application.yml +++ b/ruoyi-example/ruoyi-demo/src/main/resources/application.yml @@ -39,13 +39,19 @@ spring: # 设置默认的数据源或者数据源组,默认值即为 master primary: master datasource: - # 主库数据源 master: - type: ${spring.datasource.type} + type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: ${datasource.system-master.url} - username: ${datasource.system-master.username} - password: ${datasource.system-master.password} + url: jdbc:mysql://192.168.0.60:3307/data-center_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true + username: root + password: root + # 主库数据源 +# master: +# type: ${spring.datasource.type} +# driver-class-name: com.mysql.cj.jdbc.Driver +# url: ${datasource.system-master.url} +# username: ${datasource.system-master.username} +# password: ${datasource.system-master.password} # oracle: # type: ${spring.datasource.type} # driverClassName: oracle.jdbc.OracleDriver diff --git a/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderItemMapper.xml b/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderItemMapper.xml new file mode 100644 index 00000000..cfbef9be --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderItemMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderMapper.xml b/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderMapper.xml new file mode 100644 index 00000000..26dfffff --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/resources/mapper/demo/TOrderMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/ruoyi-example/ruoyi-demo/src/test/java/org/dromara/demo/TOrderTest.java b/ruoyi-example/ruoyi-demo/src/test/java/org/dromara/demo/TOrderTest.java new file mode 100644 index 00000000..19919ce1 --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/test/java/org/dromara/demo/TOrderTest.java @@ -0,0 +1,59 @@ +package org.dromara.demo; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import org.dromara.demo.domain.TOrder; +import org.dromara.demo.mapper.TOrderMapper; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class TOrderTest { + + @Autowired + TOrderMapper torderMapper; + + //@Autowired + //TUserMapper userMapper; + + @Test + void find() { + //Order order = orderMapper.selectById(1640990702722723841L); + } + + @Test + void page() { + Page page = new Page<>(); + page.setCurrent(3L); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.orderByAsc("order_id"); + torderMapper.selectPage(page,queryWrapper); + System.out.println(page.getTotal()); + for(TOrder order : page.getRecords()){ + System.out.print(order.getTotalMoney()+" "); + } + } + + @Test + void insert() { + for(Long i = 1L; i <= 100L; i++){ + TOrder torder = new TOrder(); + torder.setUserId(i); + torder.setTotalMoney(100 + Integer.parseInt(i+"")); + torderMapper.insert(torder); + } + + } + @Test + void insertUser() { + /*User user = new User(); + user.setId(1L); + user.setUserName("abc"); + user.setAge(18); + user.setCreateTime(new Date()); + userMapper.insert(user);*/ + } + +}