我正在使用java spring。所以在資料庫中,我有一個內容表,其中有頁面ID列和內容列。在這個內容列中,有許多追蹤器的ID,以ContentJSON的形式保存。我試圖使用這個網址進行GET API:localhost:8080/eHealth/api/user/mytracker/pageId?trackerId=2。然而,它顯示的是該特定pageIds下的trackerIds串列。
我的代碼如下。 //獲取每個追蹤器的資料
@SuppressWarnings("rawtypes")
@GetMapping(value = "/mytracker/{pageId}/{trackerId}")
public ResponseEntity<?> getTrackerContent(HttpServletRequest request,
@PathVariable String pageId, @PathVariable String trackerId) throws JsonParseException, JsonMappingException, IOException {
ValidationResult validationResult = this.tokenValidator.validateUserIdentityFromRequest(request)。
if(validationResult != ValidationResult.VALID_USER) {
return this.tokenValidator.httpResponseEntityWithTemplateMessages(validationResult)。
}
User currentUser = this. tokenValidator.getUserFromToken(this.tokenValidator.resolveToken(request))。
UserContent trackerContent = this. portalService.getUserContent(currentUser, pageId, "tracker") 。
HashMap unpackedTrackerContent = this.unpackTrackerData(trackerContent)。
HashMap<String, Object> trackers = new HashMap<String, Object> ()。
trackers.put(pageId,unpackedTrackerContent)。
return ResponseEntity.ok(trackers)。
如果有任何幫助,我們將不勝感激。謝謝你
資料庫中的內容列如下:
資料庫中的內容列如下:
{"content": null,"UserContentJSON":"{"trackerData":[{"trackerId": "1", "trackerDateTime": "05-07-2020T03:47:00. 00Z","trackerIntensity":"2","trackerDuration":"1"},{"trackerId":"2","trackerDateTime":"05-07-2020T03:47:00.00Z","trackerIntensity":"2","trackerDuration":"1"},{"trackerId":"3","trackerDateTime":"05-07-2020T03:47:00. 00Z", "trackerIntensity": "2", "trackerDuration": "1"}]}","isNew": false,"ref":"tracker", "programID": "HOPE_CVD_Copy","pageID":" physicalactivity","userID":"cvdtest"}。
uj5u.com熱心網友回復:
"我正在嘗試使用這個url進行GET API。localhost:8080/eHealth/api/user/mytracker/pageId?trackerId=2。然而,它顯示的是該特定pageIds下的trackerIds串列"
。控制器期望2個@PathVariable,而不是一個@RequestParam
@GetMapping(value = "/mytracker/{pageId}/{trackerId})
public ResponseEntity<?> getTrackerContent(HttpServletRequest request,
@PathVariable String pageId, @PathVariable String trackerId) throws...{
因此,你應該做一個請求,比如。 localhost:8080/eHealth/api/user/mytracker/3/2其中3是 "pageId",2是 "trackerId"
uj5u.com熱心網友回復:
就像@Dirk說的,你的URL犯了錯誤。
你的URL應該是這樣的,
localhost:8080/eHealth/api/user/mytracker/{yourPageId}/{yourTrackerId}。
盡管如此,在你的實作中,我沒有看到變數@PathVariable String trackerId被用于任何地方。你可能需要檢查一下。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/324185.html
標籤:
