SpringBoot整合Mybatis

引入依赖


<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.2.4</version>
</dependency>

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.26</version>
</dependency>

<!--整合mybatis-->
<dependency>
  <groupId>org.mybatis.spring.boot</groupId>
  <artifactId>mybatis-spring-boot-starter</artifactId>
  <version>2.1.4</version>
</dependency>

yml文件

spring:
  mvc:
    view:
      prefix: /
      suffix: .jsp
  datasource:
    type: org.apache.commons.dbcp.BasicDataSource   #指定连接池类型
    # mysql5.xx的链接方式
    # driver-class-name: com.mysql.jdbc.Driver        #指定驱动
    # url: jdbc:mysql://localhost:3306/ssm?characterEncoding=UTF-8           #指定url
    # mysql8.xx方式
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/bootssm?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
    username: root									#指定用户名
    password: root								 	#指定密码
mybatis:
  mapper-locations: classpath:com/codegzy/mapper/*.xml  #指定mapper配置文件位置
  type-aliases-package: com.codegzy.entity              #指定起别名所在包

**入口类添加注解@MapperScan("com.codegzy.dao") **

posted @ 2021-09-07 16:18  code-G  阅读(23)  评论(0编辑  收藏  举报