【Mybaits学习】04_ 优化调试信息(log4j)
1、增加Log4j Jar包
<!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
2、新建以及配置log4j文件
log4j.properties\uFF0C log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
3、执行测试代码,已上次CRUD为例
2017-03-04 23:35:10,441 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getUser] - ==> Preparing: select * from user where id = ? 2017-03-04 23:35:10,465 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getUser] - ==> Parameters: 2(Integer) 2017-03-04 23:35:10,487 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getUser] - <== Total: 1 User [id=2, name=Jack, age=17] 2017-03-04 23:35:10,487 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.addUser] - ==> Preparing: insert into user(name,age) values(?,?) 2017-03-04 23:35:10,488 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.addUser] - ==> Parameters: niuh(String), 11(Integer) 2017-03-04 23:35:10,541 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.addUser] - <== Updates: 1 1 2017-03-04 23:35:10,542 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - ==> Preparing: select * from user 2017-03-04 23:35:10,542 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - ==> Parameters: 2017-03-04 23:35:10,551 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - <== Total: 7 [User [id=2, name=Jack, age=17], User [id=4, name=niuh, age=11], User [id=5, name=niuh, age=11], User [id=6, name=niuh, age=11], User [id=7, name=niuh, age=11], User [id=8, name=niuh, age=11], User [id=9, name=niuh, age=11]] 2017-03-04 23:35:10,552 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.deleteUser] - ==> Preparing: delete from user where id = ? 2017-03-04 23:35:10,553 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.deleteUser] - ==> Parameters: 1(Integer) 2017-03-04 23:35:10,555 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.deleteUser] - <== Updates: 0 0 2017-03-04 23:35:10,556 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - ==> Preparing: select * from user 2017-03-04 23:35:10,556 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - ==> Parameters: 2017-03-04 23:35:10,562 [main] DEBUG [nh.ui.automation.tools.mapper.UserMapper.getAllUser] - <== Total: 7 [User [id=2, name=Jack, age=17], User [id=4, name=niuh, age=11], User [id=5, name=niuh, age=11], User [id=6, name=niuh, age=11], User [id=7, name=niuh, age=11], User [id=8, name=niuh, age=11], User [id=9, name=niuh, age=11]]