Table of Contents
SpringBoot prints the execution sql of mybatis
1. Usage scenarios
2. Specific implementation
SpringBoot turns on mybatis’s sql printing
Solution
Home Java javaTutorial How does SpringBoot print the execution sql problem of mybatis?

How does SpringBoot print the execution sql problem of mybatis?

May 15, 2023 pm 10:55 PM
sql mybatis springboot

    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文件所在包路径

    How does SpringBoot print the execution sql problem of mybatis?

    For example, I use the second method as follows:

    The mybatis configuration in application.yml is modified as follows:

    How does SpringBoot print the execution sql problem of mybatis?

    You can see the execution effect as follows:

    How does SpringBoot print the execution sql problem of mybatis?

    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!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

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

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1502
    276
    MySQL: A Practical Application of SQL MySQL: A Practical Application of SQL May 08, 2025 am 12:12 AM

    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.

    Comparing SQL and MySQL: Syntax and Features Comparing SQL and MySQL: Syntax and Features May 07, 2025 am 12:11 AM

    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.

    Where to start writing SQL code? How to start writing SQL code? Guide to starting point of writing SQL code? Where to start writing SQL code? How to start writing SQL code? Guide to starting point of writing SQL code? Jun 04, 2025 pm 07:27 PM

    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.

    SQL's Versatility: From Simple Queries to Complex Operations SQL's Versatility: From Simple Queries to Complex Operations May 05, 2025 am 12:03 AM

    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.

    How Can I Use Regular Expressions for More Powerful Pattern Matching in SQL? How Can I Use Regular Expressions for More Powerful Pattern Matching in SQL? May 27, 2025 am 12:02 AM

    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.

    SQL and Data Analysis: Extracting Insights from Information SQL and Data Analysis: Extracting Insights from Information May 04, 2025 am 12:10 AM

    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 usage of in sql is comprehensively understood the usage and scenarios of in sql. The usage of in sql is comprehensively understood the usage and scenarios of in sql. Jun 04, 2025 pm 07:57 PM

    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

    What is the purpose of the DISTINCT keyword in a SQL query? What is the purpose of the DISTINCT keyword in a SQL query? Jul 02, 2025 am 01:25 AM

    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

    See all articles