2013-12-11 95 views
3

我正在使用Spring MVC 3.1.3。Spring @RequestMapping on controller

我想要做的一樣,在documentation所示的例子。控制器上的@RequestMapping和「根」方法。

但是,Spring無法正確處理。

這裏是我的代碼:

@Controller 
@RequestMapping("/test") 
public class TestController { 
    @RequestMapping(method = RequestMethod.GET) 
    @ResponseBody 
    public String list() { 
     return "test"; 
    } 
} 

當我嘗試http://localhost/test-project/test我得到一個404未找到,但它的工作,當我使用http://localhost/test-project/test/

有誰知道我該如何解決這個問題?

感謝,

大煙

編輯:

這裏的日誌:

16:13:36,085 | DEBUG | RequestMappingHandlerMapping:209 | Looking up handler method for path /test 
16:13:36,087 | DEBUG | RequestMappingHandlerMapping:219 | Did not find handler method for [/test] 

回答

1

變化的方法,該方法requestMapping標籤...

@RequestMapping(value = {"", "/", "/list"}, method = RequestMethod.GET) 

編輯從另外的評論:

您是否嘗試過在你的控制器級@RequestMapping控制器設置爲@RequestMapping("/test*")

+0

已經嘗試過。對不起,我沒有指定。我在問題中添加了日誌。 –

+1

您是否嘗試過控制器設置爲'@RequestMapping(「/測試*」)' – david99world

+0

這是很好的建議,但它不工作要麼:(。 –

0

使用通配符:

@RequestMapping("/test*")