在本篇文章中小編給大家分享了關於SpringBoot項目如何集成依賴Mybatis的相關知識點內容,有興趣的朋友們學習下。
SpringBoot項目要如何集成依賴Mybatis呢,請跟着小編按以下步驟操作
先新建或者打開你的springboot項目
打開你的pom.xml文件,定位的依賴的配置部分,然後加入以下依賴,這是依賴mybatis框架
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency>
接着再加入以下依賴,這是指定mybatis框架的實現技術爲mysql數據庫,這裏不需要配置具體數據庫的版本.
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
在resource目錄下創建一個application.yml文件,在裏面配置數據庫的連接信息
如圖,根據你的實際信息按以下格式填寫數據庫的連接信息.
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/test?useunicode=true&characterEncoding=utf8 username: root password: rood
接着要告訴springboot你的Mybatis映射關係配置在哪裏,就是在yml中寫入以下配置:
mybatis: type-aliases-package: com.gyf.domain mapper-locations: classpath:mapper/*Mapper.xml
接下去就是創建domain包和mapper包,然後寫實體類,接口和映射的Mapper.xml,這一塊開始就已經是屬於mybatis的內容的,在springboot中集成mybatis的部分已經完成了.