One way is going to a custom HandlerInterceptor
implementation.
- Definition of the interceptor
public class FooViewerInterceptor extends HandlerInterceptorAdapter {
@Autowired
FooService fooService;
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception {
// if response succeeded ? http response code = 200 ?
// extract the "who" logic
// extract the fooId from request path
fooService.viewedBy(fooId, userId); // example...
}
}
- Register the interceptor. Note the path pattern specified with the custom interceptor instance.. just an example.
@Configuration
public class AppConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new FooViewerInterceptor()).addPathPatterns("/foo/**");
}
}