gpt4 book ai didi

java - 更新端点的响应对象

转载 作者:行者123 更新时间:2023-11-30 07:17:10 24 4
gpt4 key购买 nike

我使用 swagger 自动生成 SpringMVC API。现在我想手动更新一些端点。我有以下终点:

  @ApiOperation(value = "Estimation of ...", notes = "...", response = Similarity.class, responseContainer = "List")
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Similarity metrics", response = Similarity.class),
@io.swagger.annotations.ApiResponse(code = 200, message = "Unexpected error", response = Similarity.class) })
@RequestMapping(value = "/estimateSimilarity",
produces = { "application/json" },
method = RequestMethod.GET)
public ResponseEntity<HashMap<String,Double>> estimateSimilarity(
@ApiParam(value = "...", required = true)
@RequestParam(value = "term1", required = true) String term,
@ApiParam(value = "...", required = true)
@RequestParam(value = "terms", required = true) List<String> concepts)
throws NotFoundException {
Similarity similarity = new Similarity();
HashMap<String,Double> result = similarity.getEstimates(term1, terms);
return new ResponseEntity<HashMap<String,Double>>(HttpStatus.OK);
}

而不是 response = Similarity.class ,我要回HashMap<String,Double> result 。我应该如何更新上面给出的代码才能返回这个对象?

最佳答案

尝试修改 ApiOperations 响应容器。

@ApiOperation(value = "Estimation of ...", notes = "...", response = Double.class, responseContainer = "Map")

关于java - 更新端点的响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38186683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com