-
大小: 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开发指南
相关资源
- mybatis-spring-boot-starter-2.0.0.jar
- java SSM 框架
- Mybatis-generator自动生成代码时候提取数
- mybatis_plus.jar
- Springmvc视频+Spring mvc项目Mybatis SSM分布
- KafkaInterceptorDemo.zip
- mybatis-3.4.5、springMVC-5.0.4、mybatis-spri
- 基于javaweb的档案管理系统+Spring+Spri
- Mybatis-spring 1.2.3.jar包
- java web网上购物系统+毕业设计(完整
- mybatis-generator-core-1.3.2.jar
- mybatis-generator+lombok自动生成mybatis代码
- mybatis-log-plugin.jar
- mybatis-generator-core-1.3.2
- mybatis-3.2.3 jar包和源码
- mybatis-log-plugin.jar--支持最新idea2020.2
- spring boot+mybatis开发java web网页版电子
- springmvc+spring+mybatis整合所需jar
- Mybatis-spring 1.2.3.jar 整合包官方版
- mybatis-generator代码自动生成器(带根据
- 基于jsp+mysql+Spring+mybatis的SSM学生管理
- java中实现mybatis访问数据库
- mybatis-generator-core-1.3.2.zip官方绿色版
- mybatis-3.5.4.zip
- java mybatis 分页插件 代码
- MyBatis分页插件
- springboot2log4j2-动态mybatis
- 超市订单管理系统(spring boot+mybatis
- mybatis 代码生成器
- MyBatis基础教程.pptx
评论
共有 条评论