springboot 에서 sql 문 구 를 실행 하여 콘 솔 에 인쇄 합 니 다.

springboot 에서 sql 문 구 를 실행 하여 콘 솔 에 인쇄 합 니 다.
1.프로필
지구 화 문 구 를 다 쓸 때마다 누락 된 부분 을 찾 아 보충 하 는 것 을 피 할 수 없 을 것 이다.실행 중인 sql 을 콘 솔 에 인쇄 하여 sql 구문 에 문제 가 있 는 지 확인 할 수 있 습 니 다.
2.설정
설정 은 매우 간단 합 니 다.설정 파일 에 mapper 로그 단 계 를 설정 하면 됩 니 다.
3.코드

application-test.properties
#logging.level.mapper   =    
logging.level.com.shuhe360.auth.auth_main_car_api.mapper.CarConsumeRecordMapper=DEBUG
4.jpa
데이터 베 이 스 를 조작 하 는 jpa 도 콘 솔 에 인쇄 문 구 를 수 동 으로 열 수 있 습 니 다.
5.jpa 오픈

# JPA     
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
#    sql  
spring.jpa.show-sql=false
#                   (  )
spring.jpa.hibernate.ddl-auto=none
springboot 인쇄 sql 구문
설정 파일 에서 application.yml 설정 은 다음 과 같 습 니 다.
방식 1:

logging:
    level:
      com.xxx.com.dao.mapper: DEBUG //    mapper     
인쇄 된 형식 은 다음 과 같다.
2019-01-24 08:02:14.245 [http-nio-8060-exec-2] DEBUG c.s.a.m.m.U.getUsernameExistSet 159 - ==> Preparing: SELECT username FROM user_info WHERE username in ( ? , ? , ? )
2019-01-24 08:02:14.245 [http-nio-8060-exec-2] DEBUG c.s.a.m.m.U.getUsernameExistSet 159 - ==> Parameters: nike16(String), nike14(String), nike15(String)
2019-01-24 08:02:14.307 [http-nio-8060-exec-2] DEBUG c.s.a.m.m.U.getUsernameExistSet 159 - <== Total: 0
2019-01-24 08:02:14.323 [http-nio-8060-exec-2] DEBUG c.s.a.m.mapper.UserMapper.saveBatch 159 - ==> Preparing: INSERT INTO user_info ( username, password, email, telphone, birthday, createTime, updateTime ) values ( ?, ?, ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ?, ?, ? )
2019-01-24 08:02:14.323 [http-nio-8060-exec-2] DEBUG c.s.a.m.mapper.UserMapper.saveBatch 159 - ==> Parameters: nike14(String), 4f757a334d69b32b586f3694fbaaa9a9869aee184f98e009b6e02b170f92eb9f(String), [email protected](String), null, 2018-03-02 02:01:02.0(Timestamp), 2019-01-24 08:02:14.307(Timestamp), 2019-01-24 08:02:14.307(Timestamp), nike15(String), 18a1c9f3e7a69e3f72ab5d80caea96e5c90f5fada8f9a7e92238dc4242ba03f8(String), [email protected](String), null, 2018-03-02 02:01:02.0(Timestamp), 2019-01-24 08:02:14.307(Timestamp), 2019-01-24 08:02:14.307(Timestamp), nike16(String), 5912bd4ff3ae134b15347610b64d9f352dd3c89dd2fb5c495cf4699683b33271(String), [email protected](String), null, 2018-03-02 02:01:02.0(Timestamp), 2019-01-24 08:02:14.307(Timestamp), 2019-01-24 08:02:14.307(Timestamp)
2019-01-24 08:02:14.338 [http-nio-8060-exec-2] DEBUG c.s.a.m.mapper.UserMapper.saveBatch 159 - <== Updates: 3
방식 2:

mybatis
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 
인쇄 된 형식 은 다음 과 같다.
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
JDBC Connection [HikariProxyConnection@898692052 wrapping com.mysql.jdbc.JDBC4Connection@6a0c5a04] will be managed by Spring
==> Preparing: DELETE FROM user_info WHERE uid in ( ? , ? , ? )
==> Parameters: 44(Long), 45(Long), 46(Long)
<== Updates: 0
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.

좋은 웹페이지 즐겨찾기