
com.zlyx.easy.mybatis.interceptors.SqlInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easy-mybatis Show documentation
Show all versions of easy-mybatis Show documentation
An tool for java developers when using mybatis.
package com.zlyx.easy.mybatis.interceptors;
import java.sql.Connection;
import java.util.Properties;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.springframework.stereotype.Component;
import com.zlyx.easy.core.loggers.Logger;
/**
*
* @Auth 赵光
* @Describle
* @2019年1月14日 下午12:28:17
*/
@Component
@Intercepts({
@Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class, Integer.class }) })
public class SqlInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
BoundSql boundSql = statementHandler.getBoundSql();
String sql = boundSql.getSql().toLowerCase().replaceAll("\n", " ");
Logger.debug("执行日志:{}", sql);
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
String dialect = properties.getProperty("dialect");
Logger.info("mybatis intercept dialect:{}", dialect);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy