package cn.hydee.rap.base.aspect;
import cn.hydee.rap.base.dto.LoginUserDTO;
import cn.hydee.rap.base.exception.BaseException;
import cn.hydee.rap.base.exception.BizException;
import cn.hydee.rap.base.utils.UserUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
@Slf4j
@Component
@Intercepts({
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
// ,
// @Signature(method = "query", type = Executor.class, args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class})
})
@SuppressWarnings("unchecked")
public class JDBCInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws BaseException, InvocationTargetException, IllegalAccessException {
log.info("进入DML操作拦截器!");
LoginUserDTO loginUserDTO =UserUtils.getLoginUser();
if(loginUserDTO!=null&& loginUserDTO.getIsDrugSupervisor()==1){
log.error("药监无DML权限!");
throw new BizException("无DML操作权限!");
}
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target,this);
}
@Override
public void setProperties(Properties properties) {
}
}
Mybatis拦截器处理DML拦截demo
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1.创建 springboot+mybatis 应用 2.pom 文件的编写,需要配置相关数据库连接 3.配置 m...
- Mybatis Plugin 插件(拦截器)原理分析 引言 最近在看mybatis 源码,看到了mybatis p...