我正在使用Spring,我试图在发布请求后发送一个响应体。似乎Spring正在发回一些东西,但它是空的..。
第一个问题:是否可以在发送请求后发送json回复?
第二个问题:如果是,我是否必须包括一些特定的标题?
提前感谢
代码
@CrossOrigin
@ApiOperation(value = "Update an application", notes = "Update a document given its id. If a field is let empty, the value will not be updated.", response = Application.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation"),
@ApiResponse(code = 403, message = "Request could not be authorized."),
@ApiResponse(code = 500, message = "Internal Server Error."),
@ApiResponse(code = 400, message = "Malformed request.") })
@RequestMapping(value = "/update",
produces = { "application/json" },
consumes = { "application/json", "text/json" },
method = RequestMethod.POST)
public ResponseEntity<Application> updateApplication(@ApiParam(value = "ID of the document", required = true) @RequestParam(value = "docId", required = true) String docId,
@RequestBody @ApiParam(value = "Additional data given to the application" ) ApplicationData data)
throws NotFoundException {
ApplicationControllerMock dummyClass = new ApplicationControllerMock();
ResponseEntity<Application> dummyResponse = dummyClass.updateApplication(docId, data);
return dummyResponse;
}类Application是由swagger-codegen生成的类。如果我在GET方法中使用它,它只会返回一个JSON对象。
打印dummyResponse
如果我打印变量dummyResponse,就会得到以下内容:
<200 OK,class Application {
docId: cdb226df5398f564173db460b52f40de
companyId: 123
projectId: 123
rev: 2-fce2134de32fae95cee4192debef4600
docType: 3
docCreated: 2015-09-01T02:30:14Z
docDeleted: false
data: class ApplicationData {
status: string
domain: string
name: string
version: string
gaCode: string
}
id: a2cf532b721eedb542e884820b180b55
}
,{Access-Control-Allow-Credentials=[true], Access-Control-Allow-Origin=[*], Access-Control-Allow-Methods=[GET, OPTIONS, POST, HEAD], Access-Control-Allow-Headers=[Origin, X-Requested-With, Content-Type, Accept], Content-Type=[application/json], Access-Control-Max-Age=[3600]}>发布于 2015-09-17 09:20:04
我发现了问题..。@CrossOrigin自动创建这两个标头:
由于我也是手动添加它们,这两个标题出现了两次。所以,我只需要把它们移走,它就起作用了。
发布于 2015-09-16 14:29:15
是的,当请求是帖子时,可以发回回复。
您不必添加任何特定的标题。
https://stackoverflow.com/questions/32611427
复制相似问题