<dependency>
<groupId>p6spygroupId>
<artifactId>p6spyartifactId>
<version>3.9.1version>
dependency>
原先的url
和driver-class-name
修改成p6spy
的驱动和url
形式。
本质上p6spy相当于代理了jdbc操作
server:
port: 8088
spring:
datasource:
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url: jdbc:p6spy:mysql://localhost:3306/mp_high?useSSL=false&serverTimezone=GMT%2B8
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/mp_high?useSSL=false&serverTimezone=GMT%2B8
username: root
password: 123456
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 开启驼峰命名
spy.properties
文件spy.properties
文件内容:填入jdbc连接的驱动,以及日志输出配置
driverlist=com.mysql.cj.jdbc.Driver
logMessageFormat=com.p6spy.engine.spy.appender.MultiLineFormat
#logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
databaseDialectDateFormat=yyyy-MM-dd HH:mm:ss
appender=com.p6spy.engine.spy.appender.StdoutLogger
完成!然后就可以在控制台中查看到执行sql返回数据消耗的时间例如:
@Autowired
UserMapper userMapper;
@Test
public void selectTest(){
List<User> users = userMapper.selectList(null);
System.out.println(users);
}