拦截器与过滤器(三)@interface自定义注解拦截

一、例:拦截器记录用户访问模块:

1、例1:方法注解 

(1)注解定义:

package com.demo.interceptor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// 声明注解作用于方法
@Target(ElementType.METHOD)
// 声明注解运行时有效
@Retention(RetentionPolicy.RUNTIME)
public @interface LogModule {
    String moduleCode();
}

 (2)拦截器定义:

package com.demo.interceptor;

import com.demo.enums.LogModuleEnums;
import com.demo.service.LogModuleService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationContextUtils

版权声明:本文为w_t_y_y原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。