简体   繁体   English

控制器 Spring MVC 之前的自定义逻辑

[英]Custom logic before controller Spring MVC

My business is studying moving from Struts to Spring MVC.我的业务正在研究从 Struts 迁移到 Spring MVC。 We have a large set of web applications which uses the same base layer of custom logic before any application specific controller (called Action in Struts).我们有大量的 Web 应用程序,它们在任何特定于应用程序的控制器(在 Struts 中称为 Action)之前使用相同的自定义逻辑基础层。 In Struts we deal with this by having a few classes which extends the Action class.在 Struts 中,我们通过一些扩展 Action 类的类来处理这个问题。 Then the webapps extends those custom classes.然后 webapp 扩展那些自定义类。

I trying to find the good way to achieve the same result with Spring MVC (latest version 4.3.4).我试图找到使用 Spring MVC(最新版本 4.3.4)实现相同结果的方法。 From what I see handler interceptor doesn't quite fit my needs.从我看到的处理程序拦截器不太适合我的需要。 The custom logic that need to be executed can't be determined by requestMapping.需要执行的自定义逻辑无法通过 requestMapping 来确定。

Is there a way to create a custom annotation like @ControllerCustomA and @ControllerCustomB instead of @Controller that would check stuff, log, etc.有没有办法创建一个自定义注释,比如 @ControllerCustomA 和 @ControllerCustomB 而不是 @Controller 来检查内容、日志等。

and then have然后有

//check authentication, for instance
@ControllerA
public class user{
    @GetMapping("/user")
    public String getUser() {
        //application specific logic
    }
}

In your place I'd use an aspect .在你的地方,我会使用一个方面

You can configure it to intercept only methods in classes with some annotations.您可以将其配置为仅拦截带有一些注释的类中的方法。

Take a look at http://blog.javaforge.net/post/76125490725/spring-aop-method-interceptor-annotation看看http://blog.javaforge.net/post/76125490725/spring-aop-method-interceptor-annotation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM