zoukankan      html  css  js  c++  java
  • SpringBank 开发日志 一种简单的拦截器设计实现

    当交易由Action进入Service之前,需要根据不同的Service实际负责业务的不同,真正执行Service的业务逻辑之前,做一些检查工作。这样的拦截器应该是基于配置的,与Service关联起来的。

    /**
     * @author wangxin
     * @contact 408657544@qq.com
     * @date Jul 22, 2017 
     * @Description: 所有TransactionController的抽象父类,主要作用为以一种低耦合的方式调用Service
     */
    public abstract class BaseController {
        private final Logger log = LoggerFactory.getLogger(getClass());
        @SuppressWarnings("rawtypes")
        public Map callService(String service,Map request) {
            Class<?> clazz;
            try {
                clazz = Class.forName("com.springbank.service.service." + service);
                Method method = clazz.getMethod("execute", Map.class);
                Service bean = (Service) ApplicationContextUtil.getApplicationContext().getBean(clazz);
                //先执行拦截器栈
                List<Interceptor> interceptorList = (List<Interceptor>) clazz.getMethod("getInterceptorList", null).invoke(bean, null);
                for (Interceptor interceptor : interceptorList) {
                    interceptor.process();
                }
                //反射非静态方法,需要把第一个参数设置为对象
                return (Map)method.invoke(bean, request);
            } catch (ClassNotFoundException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            } catch (NoSuchMethodException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            } catch (SecurityException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            } catch (IllegalAccessException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            } catch (IllegalArgumentException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            } catch (InvocationTargetException e) {
                ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
            }
            return null;
        }
    }
  • 相关阅读:
    15.Git版本控制系统
    14.sudo 获取root权限
    13.定时任务
    12.文件权限:RWX
    相信301跳转大家都知道 rewrite
    修改mysql密码
    mod_rewrite是Apache的一个非常强大的功能
    mysql 常用命令集锦[绝对精华]
    mysql安装完之后,登陆后发现只有两个数据库
    mysql命令
  • 原文地址:https://www.cnblogs.com/heben/p/7230783.html
Copyright © 2011-2022 走看看