-
大小: 7KB文件類型: .java金幣: 1下載: 0 次發布日期: 2021-05-05
- 語言: Java
- 標簽: mybati??interceptor??
資源簡介
通過mybatis攔截器將查詢語句、更新語句、刪除語句、插入語句中指定表明替換為另一個表名
代碼片段和文件信息
package?com.panpass.marketing.activity.config.web;
import?com.panpass.marketing.activity.common.util.ContextUtils;
import?org.apache.commons.lang3.StringUtils;
import?org.apache.ibatis.cache.CacheKey;
import?org.apache.ibatis.executor.Executor;
import?org.apache.ibatis.executor.parameter.ParameterHandler;
import?org.apache.ibatis.executor.statement.baseStatementHandler;
import?org.apache.ibatis.executor.statement.RoutingStatementHandler;
import?org.apache.ibatis.executor.statement.StatementHandler;
import?org.apache.ibatis.mapping.*;
import?org.apache.ibatis.plugin.*;
import?org.apache.ibatis.reflection.DefaultReflectorFactory;
import?org.apache.ibatis.reflection.metaobject;
import?org.apache.ibatis.reflection.factory.DefaultobjectFactory;
import?org.apache.ibatis.reflection.wrapper.DefaultobjectWrapperFactory;
import?org.apache.ibatis.scripting.xmltags.DynamicContext;
import?org.apache.ibatis.session.Configuration;
import?org.apache.ibatis.session.ResultHandler;
import?org.apache.ibatis.session.RowBounds;
import?org.apache.tools.ant.util.ReflectUtil;
import?org.springframework.stereotype.Component;
import?java.sql.SQLException;
import?java.sql.Statement;
import?java.util.*;
@Component
@Intercepts(
????????{
????????????????@Signature(type?=?Executor.class?method?=?“update“?args?=?{MappedStatement.class?object.class})
????????????????@Signature(type?=?Executor.class?method?=?“query“?args?=?{MappedStatement.class?object.class?RowBounds.class?ResultHandler.class})
????????????????@Signature(type?=?Executor.class?method?=?“query“?args?=?{MappedStatement.class?object.class?RowBounds.class?ResultHandler.class?CacheKey.class?BoundSql.class})
????????}
)
public?class?Myinterceptor1??implements?Interceptor?{
????private??static??ArrayList?tables?=new?ArrayList();
????static?{
????????tables.add(“ACT_CONFIG“);
????}
????@Override
????public?object?intercept(Invocation?invocation)?throws?Throwable?{
?????????object[]?args?=?invocation.getArgs();
?????????if(args.length==2){//更新
?????????????return??exectorUpdate(invocation);
?????????}else{
?????????????return??exectorQuery(invocation);
?????????}
????}
???private??object??exectorUpdate(Invocation?invocation)?throws?SQLException{
???????Executor?executor?=?(Executor)?invocation.getTarget();
???????object[]?args?=?invocation.getArgs();
???????MappedStatement?ms?=?(MappedStatement)?args[0];
???????object?parameter?=?args[1];
???????BoundSql?boundSql?=??ms.getBoundSql(parameter);
???????String??sql?=getSql(boundSql.getSql());
???????MyBoundSql??myBoundSql?=new?MyBoundSql(ms.getConfiguration()sqlboundSql.getParameterMappings()boundSql.getParameterobject());
???????additionalParameters(boundSqlmyBoundSql);
???????StatementHandler?handler?=?new?RoutingStatementHandler(executormsparameterRowBounds.DEFAULTnullmyBoundSql);
???????Statement?statement?=??handler.prepare(ms.getConfiguration().getEnvironment().getDa
- 上一篇:mysql-connection.jar
- 下一篇:正版java-rfid開發指南
評論
共有 條評論