简体   繁体   English

如何将mybatis mapper xml中执行的sql查询打印到控制台

[英]How to print the sql query executing in mybatis mapper xml to the console

Suppose I am executing below query which is there in my mapper xml:假设我正在执行以下查询,该查询存在于我的映射器 xml 中:

<select id="getData" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap">

select * from emp where empId=#{empId}          
    </select>

In the above xml empId is the dynamic value that returns the value from the key of the HashMap that is passed as parameter in above mapper xml in Mybatis.上面的xml中的empId是动态值,它从HashMap的key返回值,在Mybatis的上面的mapper xml中作为参数传入。

Is there any way to print the sql with the passed param to the console when the above select query mapped to method getData is ran.当上面映射到方法 getData 的选择查询运行时,有什么方法可以将带有传递的参数的 sql 打印到控制台。

for example I pass data empId =1 I want in console : select * from emp where empId=1例如我在控制台中传递数据 empId =1 我想要: select * from emp where empId=1

add log4j.properties添加 log4j.properties

log4j.logger.yourmapperpackage=DEBUG

and the sql debug is like this:和sql调试是这样的:

2016-01-09 20:51:10,621 DEBUG [com.xxxMapper.insert] - <==>  Preparing: INSERT INTO video_info (content, id, create_time, title, media_url, zhan_count, cover_url) VALUES (?, ?, ?, ?, ?, ?, ?) >
2016-01-09 20:51:10,627 DEBUG [com.xxxMapper.insert] - <==> Parameters: vcontent(String), 0(Long), 2016-01-09 20:51:10.616(Timestamp), vtitle(String), null, 1(Integer), null>
2016-01-09 20:51:10,628 DEBUG [com.xxxMapper.insert] - <<==    Updates: 1>

Look for "logback.xml" in your project...\\resources\\在您的项目中查找“logback.xml”...\\resources\\

Change mybatis log level to INFO将 mybatis 日志级别更改为 INFO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM