悦书阁 悦书阁
首页
学习笔记
技术文档
idea插件开发
更多
  • 分类
  • 标签
  • 归档

Felix

大道至简 知易行难
首页
学习笔记
技术文档
idea插件开发
更多
  • 分类
  • 标签
  • 归档
  • 部署文档

  • 常用手册

  • 经验技巧

    • stream使用
    • Oracle笔记
    • AES加解密
    • Git技巧备忘
    • Feign支持BasicAuth验证
    • Feign远程调用
    • Mybatis-xml语法备忘
    • 邮件发送自定义Excel
    • SpringBoot集成第三方组件
      • 集成Mybatis-plus
        • pom配置添加
        • 配置文件
        • 主从方式
        • druid方式
        • p6spy 配置(日志打印)
        • 配置类
    • SpringBoot集成问题记录
    • mybaits plus 代码生成器
    • 阿尔萨斯(Arthas)
  • 技术文档
  • 经验技巧
liufei379
2022-07-18
目录

SpringBoot集成第三方组件

# 集成Mybatis-plus

# pom配置添加

<dynamic-datasource.version>3.2.0</dynamic-datasource.version>
<oracle-jdbc.version>19.3.0.0</oracle-jdbc.version>
<mybatis-plus-boot.version>3.5.1</mybatis-plus-boot.version>
<p6spy.version>3.9.1</p6spy.version>
<!-- 主从配置 -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
    <version>${dynamic-datasource.version}</version>
</dependency>

<!-- 数据库驱动 -->
<dependency>
    <groupId>com.oracle.ojdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>${oracle-jdbc.version}</version>
</dependency>

<!-- mybatis-plus -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>${mybatis-plus-boot.version}</version>
</dependency>

<!-- SQL 日志打印 test环境用 影响性能 生产不用 -->
<dependency>
    <groupId>p6spy</groupId>
    <artifactId>p6spy</artifactId>
    <version>${p6spy.version}</version>
</dependency>

<!-- 德鲁伊方式
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>druid-spring-boot-starter</artifactId>
	<version>1.1.22</version>
</dependency> -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# 配置文件

# 主从方式
spring:
 datasource:
    dynamic:
      primary: master
      p6spy: true
      datasource:
        master:
          username: test
          password: test
          url: jdbc:p6spy:oracle:thin:@ip:1521:orcl
#          url: jdbc:oracle:thin:@ip:1521/jtitest
          driver-class-name: com.p6spy.engine.spy.P6SpyDriver
        slave:
          username: test
          password: test
          url: jdbc:p6spy:oracle:thin:@ip:1521:orcl
          driver-class-name: com.p6spy.engine.spy.P6SpyDriver
      druid:
        initialSize: 20
        minIdle: 20
        maxActive: 100
        maxWait: 60000
        # 开启wall filter
        filter:
          wall:
            enabled: true
            config:
              # 检查UPDATE语句的WHERE子句是否是一个永真条件
              update-where-alay-true-check: true
              # 检查UPDATE语句是否无where条件,这是有风险的,但不是SQL注入类型的风险
              update-where-none-check: true
              # 检查DELETE语句是否无where条件
              delete-where-none-check: true
              # 检查DELETE语句的WHERE子句是否是一个永真条件
              delete-where-alway-true-check: true
            # 对被认为是攻击的SQL进行LOG.error输出
            log-violation: true
            # 对被认为是攻击的SQL抛出SQLException
            throw-exception: true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# druid方式

spring:
  datasource:
	druid:
#      driver-class-name: oracle.jdbc.OracleDriver
      driver-class-name: com.p6spy.engine.spy.P6SpyDriver
      type: com.alibaba.druid.pool.DruidDataSource
#      url: jdbc:oracle:thin:@ip:1521/jtitest
      url: jdbc:p6spy:oracle:thin:@ip:1521/jtitest
      username: test
      password: test
      initialSize: 20
      minIdle: 20
      maxActive: 100
      maxWait: 60000
      # 开启wall filter
      filter:
        wall:
          enabled: true
          config:
            # 检查UPDATE语句的WHERE子句是否是一个永真条件
            update-where-alay-true-check: true
            # 检查UPDATE语句是否无where条件,这是有风险的,但不是SQL注入类型的风险
            update-where-none-check: true
            # 检查DELETE语句是否无where条件
            delete-where-none-check: true
            # 检查DELETE语句的WHERE子句是否是一个永真条件
            delete-where-alway-true-check: true
          # 对被认为是攻击的SQL进行LOG.error输出
          log-violation: true
          # 对被认为是攻击的SQL抛出SQLException
          throw-exception: true
          # 解决p6spy问题
          dbType: oracle
          
# 日志打印 日志级别设置          
logging:
  level:
    root: info
    com:
      felix:
        manage:
          mapper: debug         
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# p6spy 配置(日志打印)

#3.2.1以上使用
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
#3.2.1以下使用或者不配置
#modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
#日志输出到控制台
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
# 使用日志系统记录 sql
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 设置 p6spy driver 代理
deregisterdrivers=true
# 取消JDBC URL前缀
useprefix=true
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset
# 日期格式
dateformat=yyyy-MM-dd HH:mm:ss
# 实际驱动可多个
#driverlist=org.h2.Driver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 2 秒
outagedetectioninterval=2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 配置类

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis plus 分页查询
 */
@Configuration
@MapperScan({"com.jti.manage.mapper"})
public class MybatisPlusConfig {


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));
        //防全表更新和删除
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return interceptor;
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
上次更新: 2026/3/11 21:47:04
邮件发送自定义Excel
SpringBoot集成问题记录

← 邮件发送自定义Excel SpringBoot集成问题记录→

最近更新
01
实现idea开发的关键步骤
10-05
02
Redis高可用架构
09-09
03
Zookeeper高可用
08-31
更多文章>
Theme by Vdoing | Copyright © 2022-2026 Felix | 粤ICP备17101757号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式