Mybatis開啟控制臺打印sql語句方式
Mybatis開啟控制臺打印sql語句
1.無論使用mybatis-plus還是mybatis
只要在springboot的配置文件----appcation.yml中添加:就可以答應(yīng)sql
logging:
level:
org.jeecg.modules.hdx.mapper: debugorg.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ù)庫ID自增",1:"該類型為未設(shè)置主鍵類型", 2:"用戶輸入ID",3:"全局唯一ID (數(shù)字類型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
id-type: 4
# 默認(rèn)數(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日志顯示,這里使用標(biāo)準(zhǔn)顯示 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 數(shù)據(jù)庫中如果有類似 如 user_name 等命名,會將 _后的字母大寫,這里是為了和實(shí)體類對應(yīng) 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>
<!--快速操作實(shí)體類-->
<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>
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot整合Shiro的環(huán)境搭建教程
這篇文章主要為大家詳細(xì)介紹了SpringBoot整合Shiro的環(huán)境搭建教程,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以了解一下2022-12-12
IDEA的Mybatis Log Plugin插件配置和使用詳解
這篇文章主要介紹了IDEA的Mybatis Log Plugin插件配置和使用,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09
使用IntelliJ IDEA查看類的繼承關(guān)系圖形(圖文詳解)
這篇文章主要介紹了使用IntelliJ IDEA查看類的繼承關(guān)系圖形,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的工作或?qū)W習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
JAVA用遞歸實(shí)現(xiàn)全排列算法的示例代碼
這篇文章主要介紹了JAVA用遞歸實(shí)現(xiàn)全排列算法的相關(guān)資料,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
Springboot整合Jedis實(shí)現(xiàn)單機(jī)版或哨兵版可切換配置方法
這篇文章主要介紹了Springboot整合Jedis實(shí)現(xiàn)單機(jī)版或哨兵版可切換配置方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-11-11
MyBatisPlus利用Service實(shí)現(xiàn)獲取數(shù)據(jù)列表
這篇文章主要為大家詳細(xì)介紹了怎樣使用 IServer 提供的 list 方法查詢多條數(shù)據(jù),這些方法將根據(jù)查詢條件獲取多條數(shù)據(jù),感興趣的可以了解一下2022-06-06
java實(shí)現(xiàn)圖片寫入高清字體及帶邊框的方法
這篇文章主要介紹了java實(shí)現(xiàn)圖片寫入高清字體及帶邊框的方法,涉及java針對圖片及文字的相關(guān)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

