2016-11-21 51 views
0

我休息控制器設置像下面處理正斜槓彈簧MVC其餘

@RequestMapping(value = {"getDataFromSpaceForType/{gridName}/{spaceName}/{dataType}/{fieldNames}/{criteria}"}, method = GET, produces = "application/json") 
    public EntriesForTypeName getDataFromSpaceForType(@PathVariable Map<String, String> dataRequestVariables) throws Exception { 

的最後一個字段的標準可以包含多個正斜槓。我無法處理這種情況。它打破了404錯誤

另外我不知道有多少斜槓可能會來,所以它成爲不可能創建多個方法。

+0

可能的複製[春季3 RequestMapping的:獲取路徑值](http://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value) –

+0

@DanielOlszewski我看了一下,但似乎接受的答案不適用於春天啓動 –

+0

你使用什麼值 request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE) – kuhajeyan

回答

0

如果您知道您的網址可能包含斜槓,您只需在發送/使用URL之前對URL進行編碼。

如果您的前端是angularJS那麼你可以做這樣的:

How to generate url encoded anchor links with AngularJS?

或者,如果你使用jquery則:

URL Encode a string in jQuery for an AJAX request

+0

我試過編碼url這樣的東西,但它沒有奏效。 encodeURIComponent方法('/休息/查詢/ getDataFromSpaceForType /本地/ privatespace/verifiedbill/feedmap/CalculatedMeasure = /下注/本地/ MXR/20160505/EOD_UK_IR_A2_20160505_1.txt) –