Răsfoiți Sursa

代码配置

赵冬冬 4 ani în urmă
părinte
comite
32574ba662

+ 0 - 5
pom.xml

@@ -52,11 +52,6 @@
             <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
             <version>${shardingsphere.version}</version>
         </dependency>
-        <dependency>
-            <groupId>io.shardingsphere</groupId>
-            <artifactId>sharding-jdbc-core</artifactId>
-            <version>${shardingsphere.version}</version>
-        </dependency>
 
         <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
         <dependency>

+ 2 - 1
src/main/java/com/xin/shardingspherejdbcdemo/ShardingsphereJdbcStudyApplication.java

@@ -1,10 +1,11 @@
 package com.xin.shardingspherejdbcdemo;
 
+import org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
-@SpringBootApplication
+@SpringBootApplication(exclude = {SpringBootConfiguration.class})
 @MapperScan("com.xin.shardingspherejdbcdemo.mapper")
 public class ShardingsphereJdbcStudyApplication {
 

+ 0 - 2
src/main/java/com/xin/shardingspherejdbcdemo/service/impl/UserServiceImpl.java

@@ -8,12 +8,10 @@ import com.xin.shardingspherejdbcdemo.entity.User;
 import com.xin.shardingspherejdbcdemo.entity.vo.PageVo;
 import com.xin.shardingspherejdbcdemo.mapper.UserMapper;
 import com.xin.shardingspherejdbcdemo.service.UserService;
-import com.xin.shardingspherejdbcdemo.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
 import java.util.List;
 
 

+ 59 - 53
src/main/resources/application.yml

@@ -2,7 +2,13 @@ server:
   port: 8087
 pagehelper:
   helper-dialect: mysql
-
+mybatis:
+  type-aliases-package: com.xin.shardingspherejdbcdemo.entity
+  mapper-locations: classpath:mapper/*Mapper.xml
+  configuration:
+    map-underscore-to-camel-case: true
+    default-fetch-size: 500
+    default-statement-timeout: 80
 dbinfo:
   dbname: study
   url: jdbc:mysql://192.168.29.131:3306/${dbinfo.dbname}
@@ -11,55 +17,55 @@ dbinfo:
 spring:
   main:
     allow-bean-definition-overriding: true
-  datasource:
-    name: mysql_test
-    type: com.alibaba.druid.pool.DruidDataSource
-    #druid相关配置
-    druid:
-      #监控统计拦截的filters
-      filters: stat
-      driver-class-name: com.mysql.jdbc.Driver
-      #基本属性
-      url: ${dbinfo.url}?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
-      username: ${dbinfo.username}
-      password: ${dbinfo.password}
-      #配置初始化大小/最小/最大
-      initial-size: 1
-      min-idle: 1
-      max-active: 20
-      #获取连接等待超时时间
-      max-wait: 60000
-      #间隔多久进行一次检测,检测需要关闭的空闲连接
-      time-between-eviction-runs-millis: 60000
-      #一个连接在池中最小生存的时间
-      min-evictable-idle-time-millis: 300000
-      validation-query: SELECT 'x'
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 20
-  shardingsphere:
-    datasource:
-      #数据库别名
-      names: master0
-      master0:
-        type: com.alibaba.druid.pool.DruidDataSource
-        driver-class-name: com.mysql.cj.jdbc.Driver
-        url: ${dbinfo.url}?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
-        username: ${dbinfo.username}
-        password: ${dbinfo.password}
-    sharding:
-      tables:
-        #逻辑表名
-        user:
-          actual-data-nodes: master0.user$->{0..2}
-          table-strategy:
-            inline:
-              sharding-column: id
-              algorithm-expression: user$->{id%3}
-    #打印sql
-    props:
-      sql:
-        show: true
+#  datasource:
+#    name: mysql_test
+#    type: com.alibaba.druid.pool.DruidDataSource
+#    #druid相关配置
+#    druid:
+#      #监控统计拦截的filters
+#      filters: stat
+#      driver-class-name: com.mysql.jdbc.Driver
+#      #基本属性
+#      url: ${dbinfo.url}?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
+#      username: ${dbinfo.username}
+#      password: ${dbinfo.password}
+#      #配置初始化大小/最小/最大
+#      initial-size: 1
+#      min-idle: 1
+#      max-active: 20
+#      #获取连接等待超时时间
+#      max-wait: 60000
+#      #间隔多久进行一次检测,检测需要关闭的空闲连接
+#      time-between-eviction-runs-millis: 60000
+#      #一个连接在池中最小生存的时间
+#      min-evictable-idle-time-millis: 300000
+#      validation-query: SELECT 'x'
+#      test-while-idle: true
+#      test-on-borrow: false
+#      test-on-return: false
+#      #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
+#      pool-prepared-statements: false
+#      max-pool-prepared-statement-per-connection-size: 20
+#  shardingsphere:
+#    datasource:
+#      #数据库别名
+#      names: master0
+#      master0:
+#        type: com.alibaba.druid.pool.DruidDataSource
+#        driver-class-name: com.mysql.cj.jdbc.Driver
+#        url: ${dbinfo.url}?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
+#        username: ${dbinfo.username}
+#        password: ${dbinfo.password}
+#    sharding:
+#      tables:
+#        #逻辑表名
+#        user:
+#          actual-data-nodes: master0.user$->{0..2}
+#          table-strategy:
+#            inline:
+#              sharding-column: id
+#              algorithm-expression: user$->{id%3}
+#    #打印sql
+#    props:
+#      sql:
+#        show: true