我們有一個Spring MVC應用程序,大多數REST操作是每個資源唯一的GET操作。所以目前我們有很多控制器,只有GET方法,彼此沒有區別(甚至在URL,內容類型,參數等等)。有多個資源有一個控制器的優點和缺點
爲了消除這種重複,我們的團隊成員提供了一個只有GET操作的控制器和一個帶有服務(資源名稱 - >資源服務)的映射。
但是我們認爲這樣的缺點更復雜Spring注入優化,沒有機會在內容類型,參數上添加一些限制 - 用一個詞自定義操作。此外,還有幾個資源駐留在單獨的控制器中。另外我不希望至少有簡單的方法來以多種方式記錄Swagger中唯一的方法(具有不同的描述)。
因此,對我來說,一方面是較少的代碼,另一方面是受限制的操作定製機會,混合體繫結構,缺乏適當的文檔或至少複雜的配置。我認爲在這裏做一個方法並不是一個好方法。
對嗎?如果是這樣,我怎麼能證明它。如果不是爲什麼?感謝您的時間和想法!
謝謝你的比較這樣的想法,我真的很感謝你抽出時間做答案!但是我沒有看到vanilla servlet之間的體系結構差異,那麼:C這種情況似乎與使用命令模式相似 –
1.通過將重複代碼引入父級AbstractController和2.您有擴展點來更改behaivor(差異你的隊友建議:單個控制器難以擴展) – ADS
作爲替代方案有多個GET方法的控制器? –