|
@@ -1,7 +1,6 @@
|
|
|
client需要复制的文件
|
|
|
|
|
|
-- MybatisPlusConfig
|
|
|
-- 数据库链接配置
|
|
|
+- 引用
|
|
|
```xml
|
|
|
<!--mysql-->
|
|
|
<dependency>
|
|
@@ -25,4 +24,66 @@ client需要复制的文件
|
|
|
<artifactId>druid</artifactId>
|
|
|
<version>1.2.0</version>
|
|
|
</dependency>
|
|
|
-```
|
|
|
+```
|
|
|
+
|
|
|
+- MybatisPlusConfig
|
|
|
+```java
|
|
|
+import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
+import org.apache.ibatis.reflection.MetaObject;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class MybatisPlusConfig implements MetaObjectHandler {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insertFill(MetaObject metaObject) {
|
|
|
+ this.setFieldValByName("createTime", new Date(), metaObject);
|
|
|
+ this.setFieldValByName("updateTime", new Date(), metaObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateFill(MetaObject metaObject) {
|
|
|
+ this.setFieldValByName("updateTime", new Date(), metaObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页插件配置
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
|
|
+ return interceptor;
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+- 数据库链接配置
|
|
|
+```yaml
|
|
|
+spring:
|
|
|
+ jackson:
|
|
|
+ date-format: yyyy-MM-dd HH:mm:ss
|
|
|
+ datasource:
|
|
|
+ url: jdbc:mysql://localhost:3306/aj_report?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
|
|
|
+ username: root
|
|
|
+ password: root
|
|
|
+ #数据源连接池配置
|
|
|
+ druid:
|
|
|
+ initial-size: 10 # 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
|
|
|
+ min-idle: 10 # 最小连接池数量
|
|
|
+ maxActive: 200 # 最大连接池数量
|
|
|
+ maxWait: 3000 # 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置
|
|
|
+ timeBetweenEvictionRunsMillis: 60000 # 关闭空闲连接的检测时间间隔.Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。
|
|
|
+ minEvictableIdleTimeMillis: 300000 # 连接的最小生存时间.连接保持空闲而不被驱逐的最小时间
|
|
|
+ testWhileIdle: true # 申请连接时检测空闲时间,根据空闲时间再检测连接是否有效.建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRun
|
|
|
+ poolPreparedStatements: true # 开启PSCache
|
|
|
+ maxPoolPreparedStatementPerConnectionSize: 20 #设置PSCache值
|
|
|
+ connectionErrorRetryAttempts: 3 # 连接出错后再尝试连接三次
|
|
|
+ breakAfterAcquireFailure: true # 数据库服务宕机自动重连机制
|
|
|
+ timeBetweenConnectErrorMillis: 300000 # 连接出错后重试时间间隔
|
|
|
+```
|