2016-09-20 43 views
-1

我正在使用Swagger在API上工作,我一直在試圖弄清楚ResponseEntity是什麼,它是如何工作的,以及爲什麼使用ResponseEntity?這ResponseEntity是什麼?

當我運行API,並轉到localhost:8080/suspect-api/swagger-ui.html。我可以輸入嫌疑人ID和品牌,並調用getSuspect方法。

在英語中,它在背景中做了什麼以及ResponseEntity的目的是什麼?

請參閱下面的代碼:

public ResponseEntity<Suspects> getSuspects(@ApiParam(value = "Brand", required = true) @PathVariable String brand, 
               @ApiParam(value = "ID", required = true) @PathVariable Long suspectId, 
               Pageable page, PagedResourcesAssembler assembler) { 
    return service.getSuspects(brand, suspectId, page, assembler); 
} 

我已經習慣了返回特定類型(如String),整型,布爾或類似學生甚至是自定義的Java對象的方法。

+1

http://docs.spring.io/spring-framework/docs/current/javadoc- API /組織/ springframework的/ HTTP/ResponseEntity.html –

回答

0

已經有一段時間了,但我認爲它最終被點擊了。

ResponseEntity其中T是任何類型,只是用HTTP代碼包裝'T'。

例如,如果你創建了一個簡單的彈簧啓動應用程序,它具有檢索員工的方法:

public ResponseEntity<Employee> getEmployee(...) { 
    // implementation here 
}