springboot+mybatis-plus 兩種方式打印sql語句的方法
1.注解方式,yml文件配置上以下就可以直接使用
mybatis-plus: mapper-locations: classpath:mapper/*.xml configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2.這一種網(wǎng)上沒有,搜過好多資料都沒有,我是配置多數(shù)據(jù)源,所以是在代碼中寫的config那么yml文件就是失效的,只能一個(gè)一個(gè)配置,到了打印sql的時(shí)候,就怎么都是找不到,后來設(shè)置的源碼找到靈感,發(fā)現(xiàn)可以使用,特此記下,方便其他小伙伴遇到同樣的問題使用。
@Bean('sqlSessionFactory') public SqlSessionFactory sqlSessionFactory() throws Exception { // 導(dǎo)入mybatissqlsession配置 MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean(); // 指明數(shù)據(jù)源 sessionFactory.setDataSource(multipleDataSource(dataSource0(), dataSource1(), dataSource2())); // 指明mapper.xml位置(配置文件中指明的xml位置會(huì)失效用此方式代替,具體原因未知) sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources('classpath*:/mapper/**Mapper.xml')); // 指明實(shí)體掃描(多個(gè)package用逗號(hào)或者分號(hào)分隔) sessionFactory.setTypeAliasesPackage('gsa.geographic.system.entity'); // 導(dǎo)入mybatis配置 MybatisConfiguration configuration = new MybatisConfiguration(); configuration.setJdbcTypeForNull(JdbcType.NULL); configuration.setMapUnderscoreToCamelCase(true); configuration.setCacheEnabled(false); // 配置打印sql語句 configuration.setLogImpl(StdOutImpl.class); sessionFactory.setConfiguration(configuration); // 添加分頁功能 sessionFactory.setPlugins(new Interceptor[]{paginationInterceptor() }); // 導(dǎo)入全局配置 sessionFactory.setGlobalConfig(globalConfiguration()); return sessionFactory.getObject(); }
主要就是這句
點(diǎn)擊setLogImpl看源碼,找到Configuration()構(gòu)造方法,就可以看見了
訪問一下看一下控制臺(tái)
到此這篇關(guān)于springboot+mybatis-plus 兩種方式打印sql語句的方法的文章就介紹到這了,更多相關(guān)springboot+mybatis-plus打印sql內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Docker究竟是什么 為什么這么流行 它的優(yōu)點(diǎn)和缺陷有哪些?2. ASP.NET MVC實(shí)現(xiàn)城市或車型三級(jí)聯(lián)動(dòng)3. Python使用Pyqt5實(shí)現(xiàn)簡易瀏覽器(最新版本測試過)4. Element ui tree(樹)實(shí)現(xiàn)父節(jié)點(diǎn)選中時(shí)子節(jié)點(diǎn)不選中父節(jié)點(diǎn)取消時(shí)子節(jié)點(diǎn)自動(dòng)取消功能5. 如何在.net6webapi中使用自動(dòng)依賴注入6. 用python登錄帶弱圖片驗(yàn)證碼的網(wǎng)站7. 如何使用瀏覽器擴(kuò)展篡改網(wǎng)頁中的JS 文件8. .NET 6實(shí)現(xiàn)滑動(dòng)驗(yàn)證碼的示例詳解9. python軟件測試Jmeter性能測試JDBC Request(結(jié)合數(shù)據(jù)庫)的使用詳解10. java實(shí)現(xiàn)彈球小游戲
