我对Filter和Interceptor的用途有点困惑。
根据我在文档中的理解,Interceptor是在请求之间运行的。另一方面,Filter在渲染视图之前运行,但在控制器渲染响应之后运行。
那么拦截器中的postHandle()和过滤器中的doFilter()的区别在哪里呢?

应该在哪些用例中使用它的最佳实践是什么?在这张图片中,Filters和Interceptors在哪里工作?
发布于 2022-02-22 20:33:09
来自baeldung

筛选器在请求到达DispatcherServlet之前对其进行拦截,这使得它们非常适合粗粒度任务,例如:
Authentication
Logging and auditing
Image and data compression
Any functionality we want to be decoupled from Spring MVC另一方面,HandlerIntercepors截获DispatcherServlet和我们的控制器之间的请求。这是在Spring MVC框架中完成的,提供对处理程序和ModelAndView对象的访问。这减少了重复,并允许实现更细粒度的功能,例如:
Handling cross-cutting concerns such as application logging
Detailed authorization checks
Manipulating the Spring context or modelhttps://stackoverflow.com/questions/35856454
复制相似问题