2013-02-14 75 views
1

當我被要求解決問題時,通過理解代碼流,我找到了被擊中的URL,然後我轉到映射到該控制器的那個控制器特定的URL如何在彈簧註釋中找到映射到URL的控制器

我覺得過程very tedious,因爲我們有一些50控制器類和多個方法標註了網址,裏面

現在,我使用Eclipse IDE中搜索選項,並找到註釋的方法URL模式

有什麼簡單的方法,我可以得到像URL這樣的信息映射到什麼樣的方式在某某類?

如果你正在使用Spring MVC的3.X結帳鏈接請幫我在這

+1

我常想,這是基於註釋的Web編程的缺點。我喜歡我的單個XML配置文件,至少對於非重要的控制器分組。 – dbreaux 2013-02-14 14:10:35

回答

3
+0

有沒有關於如何在項目中使用它的示例? – Arun 2013-02-18 08:09:03

+1

https://github.com/rstoyanchev/spring-mvc-31-demo.git – 2013-02-18 08:28:17

+0

for spring 3.0有沒有什麼辦法可以實現這個?類** RequestMappingHandlerMapping **僅從3.1開始。如何在3.0中實現相同? – Arun 2013-02-27 11:13:59

1

也許Reflections庫可以幫助:

Reflections reflections = new Reflections("my.package", 
     new TypeAnnotationsScanner(), new MethodAnnotationsScanner()); 

Set<Class<?>> controllers = reflections.getTypesAnnotatedWith(Controller.class); 

Set<Method> requestMappings = reflections.getMethodsAnnotatedWith(RequestMapping.class);