@Intercepts({@org.apache.ibatis.plugin.Signature(
type=Executor.class,
method="update",
args={MappedStatement.class, Object.class})})
public class SqlInterceptor implements Interceptor
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object parameter = args[1];
SqlLog log = new SqlLog();
Configuration configuration = ms.getConfiguration();
Object target = invocation.getTarget();
StatementHandler handler = configuration.newStatementHandler((Executor) target, ms,
parameter, RowBounds.DEFAULT, null, null);
BoundSql boundSql = handler.getBoundSql();
//记录SQL
log.setSqlclause(boundSql.getSql());
//执行真正的方法
Object result = invocation.proceed();
//记录影响行数
log.setResult(Integer.valueOf(Integer.parseInt(result.toString())));
//记录时间
log.setWhencreated(new Date());
//TODO 还可以记录参数,或者单表id操作时,记录数据操作前的状态
//获取insertSqlLog方法
ms = ms.getConfiguration().getMappedStatement("insertSqlLog");
//替换当前的参数为新的ms
args[0] = ms;
//insertSqlLog 方法的参数为 log
args[1] = log;
//执行insertSqlLog方法
invocation.proceed();
//返回真正方法执行的结果
return result;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有