2012-02-22 109 views
2

我有一個像http://localhost:8080/api/create/請求的URL,而控制器具有下面的代碼無法將URL映射控制器

@RequestMapping(value = "/", method = RequestMethod.GET) 
    public ResponseEntity<String> getApiResponse(HttpServletRequest request) 
      throws Exception {} 

控制怎麼會涉及到這個方法?我thers任何方式在春季要做到這一點,因爲我想請求映射網址是「/」只

回答

2

它應該是:

@RequestMapping(value = "/create", method = RequestMethod.GET)

0

請求映射的一點是地圖中的每個方法到一個不同的網址。你的情況:

@RequestMapping(value="/api/create") 
0

如果你的Web應用程序是應用程序服務器上的默認Web應用程序,即你沒有要提你的URL路徑應用程序本身,你不得不說

@RequestMapping(value = "/*", method = RequestMethod.GET)

@RequestMapping(value = "/api/create/", method = RequestMethod.GET)

或將@RequestMapping詮釋類: @RequestMapping(value = "/api/", method = RequestMethod.GET) 然後標記getApiResponse法註釋 @RequestMapping(value = "/create/", method = RequestMethod.GET)

你也可以提幾個網址變成一個@RequestMapping註釋:

@RequestMapping(value = {"/api/", "/api", "/api/*", "/api/create/"})

+0

感謝您的想法,要求是一樣療法eQUEST的URL可以是任何HTTP: // localhost:8080/api/create?test =「」或http:// localhost:8080/api/create/edit但是equestMapping應該只是'/' – user1195292 2012-02-22 08:08:37

相關問題