2016-09-20 89 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 
}