Mybatis 自定义 Plugin(Interceptor) 探讨!! 急!!!

xuhaibin500 2012-08-07 03:55:14
我写了一个 mybatis 的 plugin, 可是只能拦截取到 query 和 update 方法的sql语句,而 insert 和 delete 的却没拦到,不知道怎么回事。我尝试过在注解里在加上 @Signature(method = "delete") 和 @Signature(method = "insert") ,可是这样却报错了,难不成只能拦截 query 和 update 的 ? 应该不会吧,可能是我没找到方法, 希望有这方面经验的人,指点迷津!


@Intercepts({ @Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class }),
@Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class })
})
public class LogInterceptor implements Interceptor {

private Properties properties;

public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
Object parameter = invocation.getArgs()[1];
mappedStatement.getSqlSource().getBoundSql(parameter);
BoundSql boundSql = mappedStatement.getBoundSql(parameter);

String sql = "";
if (boundSql != null && boundSql.getSql() != null && !"".equals(boundSql.getSql())) {
sql = boundSql.getSql();
}
System.out.println(sql);
return invocation.proceed();
}

public Object plugin(Object target) {
return Plugin.wrap(target, this);
}

public void setProperties(Properties properties) {
this.properties = properties;
}
}



快来人呀!!!
...全文
267 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jawf 2012-11-17
  • 打赏
  • 举报
回复
Executor interface里面没有insert和delete method,看源码就知道了。但是这里的method=“update”已经包含了SQL 的insert/update/delete statement
xuhaibin500 2012-08-07
  • 打赏
  • 举报
回复
难道就没有人用mybatis的吗? 擦 ,。。。。
xuhaibin500 2012-08-07
  • 打赏
  • 举报
回复
来个同志啊,急需帮忙啊!!!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧