My project is built with Spring boot and Mybatis, I want to see the sql query statements, what can I do?
-
There are some options given hereNathan Hughes– Nathan Hughes2019-05-16 12:03:46 +00:00Commented May 16, 2019 at 12:03
-
Another option here: stackoverflow.com/questions/2635058/ibatis-get-executed-sqlDwB– DwB2019-05-16 15:04:19 +00:00Commented May 16, 2019 at 15:04
-
Here is another one: stackoverflow.com/questions/4082834/…DwB– DwB2019-05-16 15:48:51 +00:00Commented May 16, 2019 at 15:48
-
Note: ibatis is the old name of Mybatis.DwB– DwB2019-05-16 15:49:03 +00:00Commented May 16, 2019 at 15:49
-
Possible duplicate of Spring-boot with spring-mybatis - how to force it to logging all SQL queriesRoman-Stop RU aggression in UA– Roman-Stop RU aggression in UA2019-05-17 09:43:30 +00:00Commented May 17, 2019 at 9:43
Add a comment
|
1 Answer
Assuming your mappers are in a package your.pkg.mapper, adding the following line to application.properties tells MyBatis to print statements, parameters and query results.
logging.level.your.pkg.mapper=TRACE
The below is the console output of the sample project.
2019-05-17 01:01:01.631 DEBUG 76540 --- [ main] s.m.mapper.CityMapper.selectCityById : ==> Preparing: select id, name, state, country from city where id = ?
2019-05-17 01:01:01.671 DEBUG 76540 --- [ main] s.m.mapper.CityMapper.selectCityById : ==> Parameters: 1(Long)
2019-05-17 01:01:01.705 TRACE 76540 --- [ main] s.m.mapper.CityMapper.selectCityById : <== Columns: ID, NAME, STATE, COUNTRY
2019-05-17 01:01:01.705 TRACE 76540 --- [ main] s.m.mapper.CityMapper.selectCityById : <== Row: 1, San Francisco, CA, US
2019-05-17 01:01:01.711 DEBUG 76540 --- [ main] s.m.mapper.CityMapper.selectCityById : <== Total: 1
2019-05-17 01:01:01.724 DEBUG 76540 --- [ main] s.m.mapper.HotelMapper.selectByCityId : ==> Preparing: select city, name, address, zip from hotel where city = ?
2019-05-17 01:01:01.724 DEBUG 76540 --- [ main] s.m.mapper.HotelMapper.selectByCityId : ==> Parameters: 1(Integer)
2019-05-17 01:01:01.724 TRACE 76540 --- [ main] s.m.mapper.HotelMapper.selectByCityId : <== Columns: CITY, NAME, ADDRESS, ZIP
2019-05-17 01:01:01.724 TRACE 76540 --- [ main] s.m.mapper.HotelMapper.selectByCityId : <== Row: 1, Conrad Treasury Place, William & George Streets, 4001
2019-05-17 01:01:01.725 DEBUG 76540 --- [ main] s.m.mapper.HotelMapper.selectByCityId : <== Total: 1
If you don't need query results, change the log level to DEBUG.
It also is possible to set different log level per mapper/statement.
Please see the doc for details.