
正文
SpringBoot学习:整合Mybatis,使用HikariCP超高性能数据源
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、添加pom依赖jar包:
<!--整合mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency> <!-- 超高性能连接池 -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.3.9</version>
<scope>compile</scope>
</dependency>
二、项目结构:
Mapper文件在resources目录下。并在SpringBoot入口类中添加 @MapperScan("cn.com.venus.oa.mapper") @ServletComponentScan 注解

在入口类上添加注解,配置Mapper接口的地址
@ServletComponentScan
@MapperScan("cn.com.venus.oa.mapper")
public class venusAppcliation {
...
}
@ServletComponentScan: 设置启动时spring能够扫描到我们自己编写的servlet和filter
@MapperScan: 用于扫描的mapper接口
在yml配置文件中:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:///venus
username: root
password: admin mvc:
view:
prefix: /WEB-INF/pages/
suffix: .jsp mybatis:
type-aliases-package: cn.com.venus.oa.pojo
config-location: classpath:/mybatis/mybatis-config.xml
mapper-locations: classpath:/mybatis/mappers/*.xml







