How does SpringBoot print the execution sql problem of mybatis?
SpringBoot prints the execution sql of mybatis
1. Usage scenarios
should be to track the back-end SQL statements during the development process. What caused the error. The executed SQL statements need to be printed out during the Debug process. So you need to configure SpringBoot and Mybatis to print SQL statements.
2. Specific implementation
Two ways to configure in application.properties(yml):
1. logging.level.dao package name (dao package)=debug
2. mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
2.1. Plan 1 prints all mybatis SQL
The following is the yaml file configuration, and the properties file can be translated
mybatis configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
2.2. Specify the location where the mapper file is located Package
logging: level: cn.com.demos.*.mapper: trace # 改成你的mapper文件所在包路径
For example, I use the second method as follows:
The mybatis configuration in application.yml is modified as follows:
You can see the execution effect as follows:
SpringBoot turns on mybatis’s sql printing
When debugging a Java project locally, in order to view the specific interaction with the database more intuitively, sometimes SQL printing is required.
Solution
Solution 1:
springboot does not enable mybatis log output by default, and you need to manually configure it to enable debug level printing.
Since SpringBoot has introduced spring-boot-starter-logging by default, you only need to configure it, as follows:
logging.level.cn.com.**.web.mapper=debug
Description: "cn.com.**.web.mapper" is the mapper package path.
Option 2:
Add log configuration
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
After configuration, the sql sent by mybatis will be output on the console. It is recommended to use the first way.
The above is the detailed content of How does SpringBoot print the execution sql problem of mybatis?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MySQL is popular because of its excellent performance and ease of use and maintenance. 1. Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2. Insert and query data: operate data through INSERTINTO and SELECT statements. 3. Optimize query: Use indexes and EXPLAIN statements to improve performance.

The difference and connection between SQL and MySQL are as follows: 1.SQL is a standard language used to manage relational databases, and MySQL is a database management system based on SQL. 2.SQL provides basic CRUD operations, and MySQL adds stored procedures, triggers and other functions on this basis. 3. SQL syntax standardization, MySQL has been improved in some places, such as LIMIT used to limit the number of returned rows. 4. In the usage example, the query syntax of SQL and MySQL is slightly different, and the JOIN and GROUPBY of MySQL are more intuitive. 5. Common errors include syntax errors and performance issues. MySQL's EXPLAIN command can be used for debugging and optimizing queries.

The starting point of writing SQL code is to clarify the requirements. 1) Understand the problem you want to solve and determine the relationship between the required data and tables. 2) Start designing queries from simple SELECT statements and gradually increase complexity. 3) Use visualization tools to understand table structure and consider using JOIN when queries are complex. 4) Test the query and use the EXPLAIN command to optimize performance to avoid common pitfalls such as NULL value processing and inappropriate index use.

The diversity and power of SQL make it a powerful tool for data processing. 1. The basic usage of SQL includes data query, insertion, update and deletion. 2. Advanced usage covers multi-table joins, subqueries, and window functions. 3. Common errors include syntax, logic and performance issues, which can be debugged by gradually simplifying queries and using EXPLAIN commands. 4. Performance optimization tips include using indexes, avoiding SELECT* and optimizing JOIN operations.

You can use regular expressions in SQL for more powerful pattern matching, by following steps: 1) use REGEXP or REGEXP_LIKE functions for pattern matching and data validation; 2) ensure optimized performance, especially when dealing with large data sets; 3) record and simplify complex patterns for improved maintainability. The application of regular expressions in SQL can significantly enhance data analysis and manipulation capabilities, but attention should be paid to performance and pattern complexity.

The core role of SQL in data analysis is to extract valuable information from the database through query statements. 1) Basic usage: Use GROUPBY and SUM functions to calculate the total order amount for each customer. 2) Advanced usage: Use CTE and subqueries to find the product with the highest sales per month. 3) Common errors: syntax errors, logic errors and performance problems. 4) Performance optimization: Use indexes, avoid SELECT* and optimize JOIN operations. Through these tips and practices, SQL can help us extract insights from our data and ensure queries are efficient and easy to maintain.

The IN operator is used in SQL to specify multiple values in the WHERE clause. 1) IN makes the code concise and easy to read, such as SELECTemployee_nameFROMemployeesWHEREdepartmentIN('Sales','Marketing','IT'). 2) IN is suitable for subqueries, such as SELECTproduct_name, priceFROMproductsWHEREcategory_idIN(SELECTidFROMcategoriesWHEREparent_id=10). 3) When using IN, you need to pay attention to the large list affecting performance, which can be divided into small queries or used

The DISTINCT keyword is used in SQL to remove duplicate rows in query results. Its core function is to ensure that each row of data returned is unique and is suitable for obtaining a list of unique values for a single column or multiple columns, such as department, status or name. When using it, please note that DISTINCT acts on the entire row rather than a single column, and when used in combination with multiple columns, it returns a unique combination of all columns. The basic syntax is SELECTDISTINCTcolumn_nameFROMtable_name, which can be applied to single column or multiple column queries. Pay attention to its performance impact when using it, especially on large data sets that require sorting or hashing operations. Common misunderstandings include the mistaken belief that DISTINCT is only used for single columns and abused in scenarios where there is no need to deduplicate D
