zhss_springboot整合mybatis

本文介绍了如何在Spring Boot项目中整合Mybatis,包括mybatis-spring-boot-starter的工作原理,详细步骤如pom.xml依赖引入,配置Druid连接池,编写配置管理类以及启动类的设置。
摘要由CSDN通过智能技术生成

                     zhss_springboot整合mybatis

2020:08:14 10:15

一、mybatis-spring-boot-starter的工作原理

(1)自动发现一个注册好的DataSource,之前SSM框架需要手动配置applicationContext.xml,springboot不需要直接@Configuration作用代替以前的xml配置文件

(2)自动创建一个SqlSessionFactory,并且将DataSource传入SqlSessionFactory中

(3)自动基入SqlSessionFactory创建一个SqlSessionTemplate

(4)扫描所有的Mapper,将SqlSessionTemplate注入其中,然后将Mapper注册到spring容器上下文中

二、pom.xml依赖引入

<!-- 引入mybatis-spring-boot-starter依赖,用于mybatis与spring boot整合 -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.1</version>
</dependency>
<!-- 引入mysql驱动依赖 -->
<dependency>  
    <groupId>mysql</groupId>  
    <artifactId>mysql-connector-java</artifactId>  
    <scope>runtime</scope>  
</dependency>
<!-- 引入spring-boot-starter-data-jpa依赖 -->
<dependency>  
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-data-jpa</artifactId>  
</dependency>
<!-- 引入阿里的druid连接池依赖 -->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值