SpringBoot中的Mybatis依賴問題
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項目結(jié)構(gòu)

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

