自定义注解拦截校验

注解

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CsjzCheck {
    String value();
}

注解功能类,校验抛出异常

@Aspect
@Component
public class CsjzCheckAspect extends BaseController {
    @Resource
    YkCsjzMapper ykCsjzMapper;

    public static final Logger logger = LoggerFactory.getLogger(CsjzCheckAspect.class);

    @Pointcut("@annotation(com.zdww.chis.common.csjz.CsjzCheck)")
    public void location() {
    }

    @Before("location() && @annotation(csjzCheck)")
    public void action(CsjzCheck csjzCheck) {
        String kflb = csjzCheck.value();
        if (Constants.KSSZ_KFLB_YK.equals(kflb)) {
            if ("0".equals(ykCsjzMapper.getJzbz(getOrgCode(), getYkdm(), kflb))) {
                throw new PageOutException("当前药库未建账!");
            }
        } else if (Constants.KSSZ_KFLB_YF.equals(kflb)) {
            if ("0".equals(ykCsjzMapper.getJzbz(getOrgCode(), getYfdm(), kflb))) {
                throw new PageOutException("当前药房未建账!");
            }
        } else {
            if ("0".equals(ykCsjzMapper.getJzbz(getOrgCode(), getYfdm(), kflb))) {
                throw new PageOutException("当前库房未建账!");
            }
        }
    }
}

异常类

public class PageOutException extends NullPointerException{
    public PageOutException(String s) {
        super(s);
    }
}

异常拦截重定向类

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = PageOutException.class)
    public ModelAndView pageOutExceptionHandler(HttpServletRequest req, PageOutException e){
        ModelAndView mv=new ModelAndView("error/pageOut");
        System.out.println(e.getMessage());
        mv.addObject("errMsg",e.getMessage());
        return mv;
    }
}

前端页面

<!DOCTYPE html>
<html class="his-html" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
</head>
<body class="his-body">
</div>

<script type="text/javascript" th:inline="javascript">
    var msgAlter = $.messager.alert({
        title: '提示',
        msg: '<div style="  text-align: center;padding-top:6px;font-size:14px;color:#333333;">' + [[${errMsg}]] + '</div>',
        icon: 'cusError'
    });
    msgAlter.window({
        modal: true, onBeforeClose: function () {
            $('#his_main_tab').tabs('close', $('#his_main_tab').tabs('getTabIndex', $('#his_main_tab').tabs('getSelected')))
        }
    });
</script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值