且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用MyBatis和Spring在项目中记录SQL查询

更新时间:2023-09-05 17:05:52

您可以通过Mybatis-config.xml添加Mybatis的日志记录.

You can add logging for Mybatis via it's mybatis-config.xml.

像这样添加log4j:

Add log4j like so:

mybatis-config.xml

<configuration>
  <settings>
    ...
    <setting name="logImpl" value="LOG4J"/>
    ...
  </settings>
</configuration>

然后在您的log4j.properties中,添加您想要记录的类:

Then in your log4j.properties, add the class that you'd like to log:

log4j.logger.org.mybatis.example.MyMapper=TRACE

SQL语句以DEBUG级别记录,因此将输出设置为DEBUG:

SQL statements are logged at the DEBUG level, so set output to DEBUG:

log4j.logger.org.mybatis.example=DEBUG

有关更多详细信息,请参见文档.

For more details, see the documentation.