簡體   English   中英

控制器 Spring MVC 之前的自定義邏輯

[英]Custom logic before controller Spring MVC

我的業務正在研究從 Struts 遷移到 Spring MVC。 我們有大量的 Web 應用程序,它們在任何特定於應用程序的控制器(在 Struts 中稱為 Action)之前使用相同的自定義邏輯基礎層。 在 Struts 中,我們通過一些擴展 Action 類的類來處理這個問題。 然后 webapp 擴展那些自定義類。

我試圖找到使用 Spring MVC(最新版本 4.3.4)實現相同結果的方法。 從我看到的處理程序攔截器不太適合我的需要。 需要執行的自定義邏輯無法通過 requestMapping 來確定。

有沒有辦法創建一個自定義注釋,比如 @ControllerCustomA 和 @ControllerCustomB 而不是 @Controller 來檢查內容、日志等。

然后有

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

在你的地方,我會使用一個方面

您可以將其配置為僅攔截帶有一些注釋的類中的方法。

看看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