十五、微服务学习笔记-Spring Boot-MyBatis

一、搭建数据库连接池

在pom文件中增加相关依赖

 <!-- HikariCP 主要依赖-->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>${hikaricp.version}</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <!-- 排除 springboot 默认jdbc-->
                <exclusion>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--mysql 驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

appliction.yml配置

 datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.121.130:3306/myshop?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 123456
    hikari:
      minimum-idle: 5
      idle-timeout: 600000
      maximum-pool-size: 10
      auto-commit: true
      pool-name: MyHiKariCP
      max-lifetime: 1800000
      connection-timeout: 30000
      connection-test-query: select 

 

二、整合TKMybatis

在pom文件中增加相关依赖

        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.1.5</version>
        </dependency>

appliction.yml配置

mybatis:
  type-aliases-package: com.XXXX.hello.spring.domain
  mapper-locations: classpath:mapper/*.xml

 

在项目启动类包文件外创建BaseMapper

 

posted @ 2020-08-31 11:23  榕树下的回忆  阅读(154)  评论(0编辑  收藏  举报