2016-10-17 84 views
1

如何獲取最後一個路徑變量作爲剩餘路徑?我有這樣的事情,但它不是擊中:如何獲得一個路徑變量,它是Spring MVC中路徑的其餘部分?

@RequestMapping(value = "{storageId}/{repositoryId}/{path}/**", 
       method = RequestMethod.PUT) 
@RequestMapping(value = "{storageId}/{repositoryId}/{path}/**", method = RequestMethod.PUT) 
public ResponseEntity upload(@PathVariable(name = "storageId") String storageId, 
          @PathVariable(name = "repositoryId") String repositoryId, 
          @PathVariable(name = "path") String path, 
          MultipartFile multipartFile) 
     throws ... 
{ 
    ... 
} 

在新澤西州,我可以很容易地做到這一點是這樣的:

@Path("{storageId}/{repositoryId}/{path:.*}") 

...但我必須在遷移一些代碼來春天MVC。

的問題是,如果我的網址是:

http://localhost:48080/storages/storage0/snapshots/org/foo/bar/metadata/metadata-foo/3.1-SNAPSHOT/metadata-foo-3.1-20161017.182007-1.jar 

path被截斷爲:

metadata/metadata-foo/3.1-SNAPSHOT/metadata-foo-3.1-20161017.182007-1.jar 

這顯然是不正確的,因爲它應該是:

org/foo/bar/metadata/metadata-foo/3.1-SNAPSHOT/metadata-foo-3.1-20161017.182007-1.jar 

任何的建議都受歡迎!

+0

讓我們[在聊天中繼續討論](http://chat.stackoverflow.com/rooms/125938/discussion-between-carlspring-and-sotirios-delimanolis)。 – carlspring

+3

在這裏採取一些提示窗體:http://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value –

+0

@SotiriosDelimanolis:任何想法http://stackoverflow.com/questions/40095340/is - 可能使用彈簧mvc與澤西註釋/? – carlspring

回答

0
@RequestMapping(value = "{storageId}/{repositoryId}/{path}/**", 
       method = RequestMethod.PUT) 
public ResponseEntity upload(@PathVariable(name = "storageId") String storageId, 
           @PathVariable(name = "repositoryId") String repositoryId,MultipartFile multipartFile,HttpServletRequest request) 
      throws ... 
    { 
     String restOfTheUrl = (String) request.getAttribute(
     HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); 
    } 
+0

可以嘗試打印所有三個變量並添加示例?恐怕這對我不起作用。另外,這是真的在Spring MVC中完成的嗎? – carlspring

+0

是的,這真的是這樣:https://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value?noredirect=1&lq=1 – MariuszS