• 十五、微服务学习笔记-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

  • 相关阅读:
    ElasticSearch 2 (1)
    Vagrant (2) —— 基本安装与配置(下)
    Vagrant (1) —— 基本安装与配置(上)
    Vagrant (3) —— 复制/备份Vagrant Box
    vue中$forceUpdate的使用
    vue+ElementUi 选择框选中之后翻页进行状态保持及默认选中
    loonflow 工单系统
    一些后端知识
    前端学习计划
    async/await函数的执行顺序的理解
  • 原文地址:https://www.cnblogs.com/myLeisureTime/p/13588584.html
Copyright © 2020-2023  润新知