Mybatis開啟控制臺(tái)打印sql語(yǔ)句方式
Mybatis開啟控制臺(tái)打印sql語(yǔ)句
1.無(wú)論使用mybatis-plus還是mybatis
只要在springboot的配置文件----appcation.yml中添加:就可以答應(yīng)sql
logging: level: org.jeecg.modules.hdx.mapper: debug
org.jeecg.modules.hdx.mapper為@mapper注解下面的類
- 或者繼承BaseMapper
- 或者@MapperScan掃描包的類
2.如果使用的是springboot+mybatis-plus的話
#mybatis plus 設(shè)置 mybatis-plus: mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml global-config: # 關(guān)閉MP3.0自帶的banner banner: false db-config: #主鍵類型 0:"數(shù)據(jù)庫(kù)ID自增",1:"該類型為未設(shè)置主鍵類型", 2:"用戶輸入ID",3:"全局唯一ID (數(shù)字類型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)"; id-type: 4 # 默認(rèn)數(shù)據(jù)庫(kù)表下劃線命名 table-underline: true configuration: # 這個(gè)配置會(huì)將執(zhí)行的sql打印出來(lái),在開發(fā)或測(cè)試的時(shí)候可以用 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
- 在pom文件引入依賴
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.1</version> </dependency>
3.如果使用的是springboot+mybatis的話(包含分頁(yè))
#數(shù)據(jù)庫(kù)的配置 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT username: root password: root #mybatis的配置 mybatis: configuration: # sql日志顯示,這里使用標(biāo)準(zhǔn)顯示 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 數(shù)據(jù)庫(kù)中如果有類似 如 user_name 等命名,會(huì)將 _后的字母大寫,這里是為了和實(shí)體類對(duì)應(yīng) map-underscore-to-camel-case: true # 配置mapper文件的路徑 mapper-locations: classpath:org/jeecg/modules/hdx.mapper/*/mapper/*.xml #pageHelper配置分頁(yè)(官網(wǎng)推薦配置) pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
- pom配置(包含分頁(yè))
<!--web,servlet引入--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--mybatis依賴--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.1</version> </dependency> <!--mysql依賴--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--快速操作實(shí)體類--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!--單元測(cè)試--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!—pagehelper mybatis的分頁(yè)插件依賴--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Mybatis-plus如何查詢表中指定字段(不查詢?nèi)孔侄?
這篇文章主要介紹了Mybatis-plus如何查詢表中指定字段(不查詢?nèi)孔侄?,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07springBoot解決static和@Component遇到的bug
這篇文章主要介紹了springBoot解決static和@Component遇到的bug,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02淺談mybatis 樂(lè)觀鎖實(shí)現(xiàn),解決并發(fā)問(wèn)題
這篇文章主要介紹了淺談mybatis 樂(lè)觀鎖實(shí)現(xiàn),解決并發(fā)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08Feign實(shí)現(xiàn)多文件上傳,Open?Feign多文件上傳問(wèn)題及解決
這篇文章主要介紹了Feign實(shí)現(xiàn)多文件上傳,Open?Feign多文件上傳問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11詳解快速排序算法中的區(qū)間劃分法及Java實(shí)現(xiàn)示例
這篇文章主要介紹了詳解快速排序算法中的區(qū)間劃分法及Java實(shí)現(xiàn)示例,文中分別介紹了快排時(shí)兩種區(qū)間劃分的思路,需要的朋友可以參考下2016-04-04springmvc+shiro+maven 實(shí)現(xiàn)登錄認(rèn)證與權(quán)限授權(quán)管理
Shiro 是一個(gè) Apache 下的一開源項(xiàng)目項(xiàng)目,旨在簡(jiǎn)化身份驗(yàn)證和授權(quán),下面通過(guò)實(shí)例代碼給大家分享springmvc+shiro+maven 實(shí)現(xiàn)登錄認(rèn)證與權(quán)限授權(quán)管理,感興趣的朋友一起看看吧2017-09-09springboot+Vue實(shí)現(xiàn)分頁(yè)的示例代碼
本文主要介紹了springboot+Vue實(shí)現(xiàn)分頁(yè)的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-06-06Spring實(shí)現(xiàn)三級(jí)緩存機(jī)制
三級(jí)緩存機(jī)制是Spring解決循環(huán)依賴問(wèn)題的關(guān)鍵,本文主要介紹了Spring實(shí)現(xiàn)三級(jí)緩存機(jī)制,具有一定的參考價(jià)值,感興趣的可以了解一下2025-02-02