SpringBoot中的Mybatis依賴問(wèn)題
Pom導(dǎo)入依賴
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>application.yml
#配置數(shù)據(jù)源,yml格式
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/dianping?useUnicode=true&characterEncoding=utf8
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
#指定mybatis映射文件的地址
mybatis:
mapper-locations: classpath:mapper/*.xml項(xiàng)目結(jié)構(gòu)

mybatis默認(rèn)是屬性名和數(shù)據(jù)庫(kù)字段名一一對(duì)應(yīng)的,即
數(shù)據(jù)庫(kù)表列:user_name
實(shí)體類屬性:user_name
但是java中一般使用駝峰命名
數(shù)據(jù)庫(kù)表列:user_name
實(shí)體類屬性:userName
在Springboot中,可以通過(guò)設(shè)置map-underscore-to-camel-case屬性為true來(lái)開啟駝峰功能。
application.properties中:
mybatis:
configuration:
map-underscore-to-camel-case: true補(bǔ)充:下面再看下spring boot集成mybatis需要的相關(guān)依賴
<dependencies>
<!-- 單元測(cè)試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- springboot對(duì)面向切面編程的支持,包括spring-aop和aspectj -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<!-- 通過(guò)spring-rabbit來(lái)支持AMQP協(xié)議 -->
<artifactId>spring-boot-starter-amqp</artifactId>
<!-- 對(duì)全棧web開發(fā)的支持,包括tomcat和spring-webmvc -->
<artifactId>spring-boot-starter-web</artifactId>
<!-- TODO 發(fā)布生產(chǎn)的時(shí)候需要將此段放開 -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- 支持常規(guī)的測(cè)試依賴,包括junit,hamcrest.mockito以及spring-test -->
<artifactId>spring-boot-starter-test</artifactId>
<!-- 生產(chǎn)準(zhǔn)備的特征,用于幫你監(jiān)控和管理應(yīng)用 -->
<artifactId>spring-boot-starter-actuator</artifactId>
<!--核心spring boot starter,包括自動(dòng)配置支持,日志和YAML -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<!--對(duì)jdbc數(shù)據(jù)庫(kù)的支持 -->
<artifactId>spring-boot-starter-jdbc</artifactId>
<!--對(duì)spring-security的支持 -->
<artifactId>spring-boot-starter-security</artifactId>
<!--對(duì)spring-redis的支持 ,支持Redis鍵值存儲(chǔ)數(shù)據(jù)庫(kù)-->
<artifactId>spring-boot-starter-redis</artifactId>
<!-- mybatis -->
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
<!-- MYSQL -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.30</version>
<artifactId>druid</artifactId>
<version>1.0.24</version>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.1.Final</version>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<!--pagehelper -->
<!-- <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency> -->
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
</dependencies>到此這篇關(guān)于SpringBoot中的Mybatis依賴問(wèn)題的文章就介紹到這了,更多相關(guān)SpringBoot Mybatis依賴內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
springboot項(xiàng)目中實(shí)現(xiàn)訪問(wèn)druid內(nèi)置監(jiān)控頁(yè)面
這篇文章主要介紹了springboot項(xiàng)目中實(shí)現(xiàn)訪問(wèn)druid內(nèi)置監(jiān)控頁(yè)面的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
基于SpringBoot?使用?Flink?收發(fā)Kafka消息的示例詳解
這篇文章主要介紹了基于SpringBoot?使用?Flink?收發(fā)Kafka消息,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01
聊聊Spring?Cloud?Gateway過(guò)濾器精確控制異常返回問(wèn)題
這篇文章主要介紹了Spring?Cloud?Gateway過(guò)濾器精確控制異常返回問(wèn)題,本篇任務(wù)就是分析上述現(xiàn)象的原因,通過(guò)閱讀源碼搞清楚返回碼和響應(yīng)body生成的具體邏輯,需要的朋友可以參考下2021-11-11
使用idea搭建一個(gè)spring mvc項(xiàng)目的圖文教程
這篇文章主要介紹了使用idea直接創(chuàng)建一個(gè)spring mvc項(xiàng)目的圖文教程,本文通過(guò)圖文并茂的方式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
利用consul在spring boot中實(shí)現(xiàn)分布式鎖場(chǎng)景分析
這篇文章通過(guò)場(chǎng)景分析給大家介紹如何利用consul在spring boot中實(shí)現(xiàn)簡(jiǎn)單的分布式鎖功能,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-09-09
Jdk11使用HttpClient提交Http2請(qǐng)求的實(shí)現(xiàn)方法
這篇文章主要介紹了Jdk11使用HttpClient提交Http2請(qǐng)求的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
Spring?Cloud實(shí)現(xiàn)灰度發(fā)布的示例代碼
這篇文章主要為大家詳細(xì)介紹了Spring?Cloud實(shí)現(xiàn)灰度發(fā)布的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下2023-09-09

