springboot+mybatis-plus 两种方式打印sql语句的方法
作者:渣渣洒泪成长记 时间:2022-12-29 13:41:11
1.注解方式,yml文件配置上以下就可以直接使用
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2.这一种网上没有,搜过好多资料都没有,我是配置多数据源,所以是在代码中写的config那么yml文件就是失效的,只能一个一个配置,到了打印sql的时候,就怎么都是找不到,后来设置的源码找到灵感,发现可以使用,特此记下,方便其他小伙伴遇到同样的问题使用。
@Bean("sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory() throws Exception {
// 导入mybatissqlsession配置
MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
// 指明数据源
sessionFactory.setDataSource(multipleDataSource(dataSource0(), dataSource1(), dataSource2()));
// 指明mapper.xml位置(配置文件中指明的xml位置会失效用此方式代替,具体原因未知)
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/**Mapper.xml"));
// 指明实体扫描(多个package用逗号或者分号分隔)
sessionFactory.setTypeAliasesPackage("gsa.geographic.system.entity");
// 导入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()
});
// 导入全局配置
sessionFactory.setGlobalConfig(globalConfiguration());
return sessionFactory.getObject();
}
主要就是这句
点击setLogImpl看源码,找到Configuration()构造方法,就可以看见了
访问一下看一下控制台
来源:https://blog.csdn.net/dfBeautifulLive/article/details/100700365
标签:springboot,mybatis-plus,打印sql
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现购物车及其他功能的角标
2021-12-24 10:54:54
![](https://img.aspxhome.com/file/2023/1/138411_0s.jpg)
Android刮刮卡实现原理与代码讲解
2021-08-06 13:50:42
![](https://img.aspxhome.com/file/2023/5/90185_0s.jpg)
Jmeter分布式压力测试实现过程详解
2022-03-23 21:32:44
![](https://img.aspxhome.com/file/2023/0/63040_0s.png)
SpringBoot项目依赖和配置最新示例讲解
2021-08-13 23:04:23
SpringBoot使用prometheus监控的示例代码
2021-05-29 02:37:41
![](https://img.aspxhome.com/file/2023/0/65590_0s.jpg)
一文快速掌握Spring Cloud Stream
2023-09-01 23:09:38
![](https://img.aspxhome.com/file/2023/6/73116_0s.png)
SpringBoot实现Mysql使用MD5进行密码加密的示例
2022-11-24 23:14:16
![](https://img.aspxhome.com/file/2023/6/62156_0s.png)
Java消息队列JMS实现原理解析
2023-05-14 04:02:04
![](https://img.aspxhome.com/file/2023/4/81354_0s.png)
浅谈Android ASM自动埋点方案实践
2021-10-19 22:01:18
![](https://img.aspxhome.com/file/2023/4/101824_0s.png)
基于StreamRead和StreamWriter的使用(实例讲解)
2022-09-11 22:12:36
C# 循环判断会进来几次的实现代码
2021-12-27 15:10:51
![](https://img.aspxhome.com/file/2023/9/106409_0s.jpg)
在AndroidManifest.xml中uses-sdk内属性意思
2021-10-08 17:16:09
Opencv基于CamShift算法实现目标跟踪
2023-02-15 15:39:56
![](https://img.aspxhome.com/file/2023/2/121672_0s.jpg)
java使用stream判断两个list元素的属性并输出方式
2023-02-06 14:15:18
C#在复杂多线程环境下使用读写锁同步写入文件
2021-06-16 03:45:53
![](https://img.aspxhome.com/file/2023/2/119602_0s.png)
C#如何自动识别文件的编码
2022-10-08 01:41:43
java 对象输入输出流读写文件的操作实例
2021-06-13 15:24:30
Java Spring拦截器案例详解
2022-11-01 07:15:06
C#实现将一个字符串进行翻转显示的6种方法
2022-05-07 22:55:10
![](https://img.aspxhome.com/file/2023/5/102315_0s.png)
Android中Listview点赞功能的实现
2023-06-21 11:49:59