介绍
- 对 p6spy 的进行了简单配置,然后实现引入即用
 - p6spy 是对sql的监视
 - 如果改模块不能满足你的功能、
- 要么改本模块的配置文件
 - 要么自己依赖原生的p6spy进行配置
 
 - 
引入依赖
<!-- p6spy --><dependency><groupId>cn.jdevelops</groupId><artifactId>logs-cache-p6spy</artifactId><version>2.0.2</version></dependency>
使用
 配置只需要简单的把数据库连接改下就行了
spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver spring.datasource.url=jdbc:p6spy:mysql:
server.port=1238spring.jpa.show-sql=truespring.jpa.hibernate.ddl-auto=updatespring.datasource.password=rootspring.datasource.username=rootspring.datasource.url=jdbc:p6spy:mysql://192.168.0.3:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver
示例测试
在测试jpa的时候一起用了
@PostMapping("dyFind")public ResultVO<List<UserVO>> dyFind(@RequestBody UserFindDTO user){User to = user.to(User.class);JPAUtilExpandCriteria<User> selectBean = CommUtils.getSelectBean(to);List<User> all = userService.getJpaBasicsDao().findAll(selectBean);return ResultVO.successForData(User.to(all, UserVO.class));}
- 效果
2021-12-10 16:37:57 |INFO |p6spy:60 |=====================================================连接id:1当前时间:2021-12-10 16:37:57.156类别:statement花费时间(ms):2预编译sql:select user0_.id as id1_0_, user0_.create_time as create_t2_0_, user0_.create_user_name as create_u3_0_, user0_.update_time as update_t4_0_, user0_.update_user_name as update_u5_0_, user0_.address as address6_0_, user0_.login_name as login_na7_0_, user0_.login_pwd as login_pw8_0_, user0_.name as name9_0_, user0_.phone as phone10_0_, user0_.user_icon as user_ic11_0_, user0_.user_no as user_no12_0_ from sys_user user0_ where user0_.user_no like ? or user0_.name like ?最终执行的sql:select user0_.id as id1_0_, user0_.create_time as create_t2_0_, user0_.create_user_name as create_u3_0_, user0_.update_time as update_t4_0_, user0_.update_user_name as update_u5_0_, user0_.address as address6_0_, user0_.login_name as login_na7_0_, user0_.login_pwd as login_pw8_0_, user0_.name as name9_0_, user0_.phone as phone10_0_, user0_.user_icon as user_ic11_0_, user0_.user_no as user_no12_0_ from sys_user user0_ where user0_.user_no like '%146664%' or user0_.name like '%超%'=====================================================
示例项目地址
在测试jpa的时候一起用了 https://github.com/en-o/Jdevelops-Example/tree/main/HJPA
 
