【发布时间】:2017-09-05 03:50:53
【问题描述】:
我正在使用 swagger 来记录我的其余 api。
一个例子:
@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);
}
}
如上所见,上述方法RequestMapping中的value为空(“”)。
正因为如此,这个类和方法没有被招摇。
但是当我将上述方法的 RequestMapping 行更改为如下:
@RequestMapping(method = RequestMethod.GET, value = "/")
它开始工作。
这是一个错误吗?我怎样才能使大摇大摆地使用"" 路径值。我不想把"/" 放在所有这些方法之上。
【问题讨论】:
-
您是否尝试过不指定空值?喜欢
@RequestMapping(method = RequestMethod.GET)或@GetMapping()? -
这里的
@RequestMapping是spring注解吗?另外,当它与 value="/" 一起使用时,swagger 上显示的完整路径是什么? -
@AlekseiBudiak:那行得通..谢谢!!
-
@Nik 很高兴它有帮助!
标签: java spring rest spring-mvc swagger