When requesting data in the foreground, the SQL statements are always printed to the console. One idea is to make it print to the log. How to do it?
See the mybatis configuration file below:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- Settings> <!-- Settings> <!-- Enable cache by the global mapper--> <setting name="cacheEnabled" value="true" /> <!-- When querying, turn off the associated object loading in time to improve performance--> <setting name="lazyLoadingEnabled" value="false" /> <!-- Set the form of loading of the associated object. Here is a loading field on demand (the loading field is specified by SQL). All fields of the associated table will not be loaded to improve performance--> <setting name="aggressiveLazyLoading" value="false" /> <!-- For SQL queries at locations, different result sets are allowed to be returned to achieve a common effect--> <setting name="multipleResultSetsEnabled" value="true" /> <!-- Allow to use column labels instead of listing--> <setting name="useColumnLabel" value="true" /> <!-- Allow to use custom primary key values (such as the UUID 32-bit encoding generated by the program as key values), and the pk generation strategy of the data table will be overwritten--> <setting name="useGeneratedKeys" value="true" /> <!-- Give field-attribute mapping support for nested resultMaps --> <setting name="autoMappingBehavior" value="PARTIAL" /> <!-- Cache SQL for batch update operations to improve performance --> <setting name="defaultExecutorType" value="REUSE" /> <!-- Timeout if the database has not responded for more than 25,000 seconds --> <setting name="defaultStatementTimeout" value="25,000" /> <!-- Print query statement --> <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> --> </settings> </configuration> <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <!-- Settings> <!-- Settings> <!-- Enable cache in the global mapper--> <setting name="cacheEnabled" value="true" /> <!-- When querying, turn off the associated object loading timely to improve performance --> <setting name="lazyLoadingEnabled" value="false" /> <!-- Set the form of the associated object loading, here is a loading field on demand (the loading field is specified by SQL). All fields of the associated table will not be loaded to improve performance --> <setting name="aggressiveLazyLoading" value="false" /> <!-- For SQL queries at locations, different result sets are allowed to be returned to achieve a general effect --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- Allow column labels to be used instead of listing --> <setting name="useColumnLabel" value="true" /> <!-- Allow custom primary key values (such as UUID 32-bit encoding generated by the program as key values), and the pk generation strategy of the data table will be overwritten --> <setting name="useGeneratedKeys" value="true" /> <!-- Give nested resultMap support for field-attribute mapping --> <setting name="autoMappingBehavior" value="PARTIAL" /> <!-- Cache SQL for batch update operations to improve performance --> <setting name="defaultExecutorType" value="REUSE" /> <!-- Timeout if the database has not responded for more than 25,000 seconds --> <setting name="defaultStatementTimeout" value="25000" /> <!-- Print query statement--> <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> --> </settings></configuration><setting name="logImpl" value="STDOUT_LOGGING" />
Summarize
The above is a detailed explanation of the example of the integration of mybatis in the integration of the sql into the log that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time!