SpringBoot整合MyBatis使用Druid数据源

依赖

<!-- MyBatis -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.4</version>
</dependency>
<!-- Druid数据源 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.22</version>
</dependency>
<!-- MySql依赖 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

配置

spring:
  datasource:
    url: jdbc:mysql://47.100.177.78:123456/xdcalss?useUnicode=true&characterEncoding=utf-8
    username: root
    password: monkeyz1368
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      stat-view-servlet:
        enabled: true # 激活控制台
        url-pattern: /druid/* # 访问路径
        reset-enable: false # 是否允许重置数据
        login-username: root # 账号
        login-password: root # 密码
      filter:
        stat:
          enabled: true # 记录语句统计
          
mybatis:
  configuration:
    map-underscore-to-camel-case: true  # 驼峰配置

附上properties格式的,方便查看

# druid base configure
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root

# druid console configure
spring.datasource.druid.stat-view-servlet.enabled=true # 激活控制台
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/* # 访问路径
spring.datasource.druid.filter.stat.enabled=true # 记录语句统计
spring.datasource.druid.stat-view-servlet.reset-enable=false # 是否允许重置数据
spring.datasource.druid.stat-view-servlet.login-username=root # 账号
spring.datasource.druid.stat-view-servlet.login-password=root # 密码

 # mybatis 下划线转驼峰配置,两者都可以
 #mybatis.configuration.mapUnderscoreToCamelCase=true
 mybatis.configuration.map-underscore-to-camel-case=true

然后在启动类上面加上:@MapperScan(“com.xk857.mapper”)

启动后,控制台访问地址:http://localhost:8080/druid

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lOU9yYju-1626448390574)(http://xk857.com/blog/2021/01image-20210212144906075.png)]

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CV大魔王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值