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