SpringBoot項(xiàng)目集成依賴Mybatis步驟
SpringBoot項(xiàng)目要如何集成依賴Mybatis呢,請(qǐng)跟著小編按以下步驟操作
先新建或者打開你的springboot項(xiàng)目
打開你的pom.xml文件,定位的依賴的配置部分,然后加入以下依賴,這是依賴mybatis框架
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency>
接著再加入以下依賴,這是指定mybatis框架的實(shí)現(xiàn)技術(shù)為mysql數(shù)據(jù)庫,這里不需要配置具體數(shù)據(jù)庫的版本.
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
在resource目錄下創(chuàng)建一個(gè)application.yml文件,在里面配置數(shù)據(jù)庫的連接信息
如圖,根據(jù)你的實(shí)際信息按以下格式填寫數(shù)據(jù)庫的連接信息.
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映射關(guān)系配置在哪里,就是在yml中寫入以下配置:
mybatis: type-aliases-package: com.gyf.domain mapper-locations: classpath:mapper/*Mapper.xml
接下去就是創(chuàng)建domain包和mapper包,然后寫實(shí)體類,接口和映射的Mapper.xml,這一塊開始就已經(jīng)是屬于mybatis的內(nèi)容的,在springboot中集成mybatis的部分已經(jīng)完成了.
相關(guān)文章
Springboot+AOP實(shí)現(xiàn)時(shí)間參數(shù)格式轉(zhuǎn)換
前端傳過來的時(shí)間參數(shù),后端可以自定義時(shí)間格式轉(zhuǎn)化使用,這樣想轉(zhuǎn)成什么就轉(zhuǎn)成什么。本文將利用自定義注解AOP實(shí)現(xiàn)時(shí)間參數(shù)格式轉(zhuǎn)換,感興趣的可以了解一下2022-04-04java實(shí)現(xiàn)學(xué)生選課系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)學(xué)生選課系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02SpringMVC中Controller類數(shù)據(jù)響應(yīng)的方法
這篇文章主要介紹了SpringMVC中的數(shù)據(jù)響應(yīng)的問題,主要來了解 Controller 類如何進(jìn)行數(shù)據(jù)響應(yīng)的,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-07-07jboss( WildFly)上運(yùn)行 springboot程序的步驟詳解
這篇文章主要介紹了jboss( WildFly)上運(yùn)行 springboot程序的步驟詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02java.text.DecimalFormat類十進(jìn)制格式化
這篇文章主要為大家詳細(xì)介紹了java.text.DecimalFormat類十進(jìn)制格式化的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03