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...