Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot SpringBoot中是否有与rails的before_过滤器等效的过滤器?_Spring Boot - Fatal编程技术网

Spring boot SpringBoot中是否有与rails的before_过滤器等效的过滤器?

Spring boot SpringBoot中是否有与rails的before_过滤器等效的过滤器?,spring-boot,Spring Boot,从Rails开始在SpringBoot中编程,但无法完善与before_filter相当的功能。我只想添加在调用我的控制器之前发生的简单函数您要查找的是,这些函数具有以下方法,允许您在某些事件发生时执行某些代码: 预处理(..):在执行实际控制器方法之前 postHandle(..):在执行控制器方法之后 完成后(..):完成请求后 创建HandlerInterceptor后,可以通过将其添加到InterceptorRegistry进行注册: @Configuration @EnableWe

从Rails开始在SpringBoot中编程,但无法完善与before_filter相当的功能。我只想添加在调用我的控制器之前发生的简单函数

您要查找的是,这些函数具有以下方法,允许您在某些事件发生时执行某些代码:

  • 预处理(..)
    :在执行实际控制器方法之前
  • postHandle(..)
    :在执行控制器方法之后
  • 完成后(..)
    :完成请求后
创建
HandlerInterceptor
后,可以通过将其添加到
InterceptorRegistry
进行注册:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyHandlerInterceptor());
    }
}

从文档中:
如果您想要保留Spring Boot MVC功能,并且想要添加额外的MVC配置(拦截器、格式化程序、视图控制器和其他功能),那么您可以添加自己的@configuration类,类型为WebMVCConfiguer,但不添加@EnableWebMvc
,感谢附加信息@托蒂奇,请注意这种行为
@EnableWebMvc
表示您希望完全控制SpringMVC,而忽略那些SpringBootMVC功能。但是无论您使用什么配置,都必须将拦截器添加到
InterceptorRegistry