我正在使用招摇来记录我的休息时间。
一个例子:
@RequestMapping(value = "/abc/api/fruit", produces = "application/json")
@Controller
@Api(value = "Fruit", description = "api for fruits", produces = "application/json")
public class FruitResource {
@RequestMapping(method = RequestMethod.GET, value = "")
@ResponseBody
@ApiOperation(httpMethod = "GET", value = "Resource to get fruits", produces = "application/json", notes = "get fruits", response=Fruit.class)
public ResponseEntity<Fruit> getFruits() throws Exception {
return new ResponseEntity<Fruit>(someServiceCallToGetFruits(), HttpStatus.OK);
}
}
如上所示,方法上方value
中的RequestMapping
为空(“”)。
因此,这个类和方法不会被swagger拾取。
但是当我将RequestMapping行上面的方法更改为如下所示:
@RequestMapping(method = RequestMethod.GET, value = "/")
它开始工作。
这是一个错误吗?如何使用""
路径值进行招摇。我不想把"/"
置于所有这些方法之上。
答案 0 :(得分:3)
如果您不想为特定方法添加扩展API路径,则无需明确指定空值。相反,可以使用以下注释:
@RequestMapping(method = RequestMethod.GET)
甚至
@GetMapping()