您的位置:首页 > 编程语言 > Java开发

Spring MVC中使用Swagger生成API文档

2017-06-12 15:47 477 查看
Swagger介绍

Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目

实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档。

一、常见swagger注解一览与使用

最常用的5个注解

@Api:修饰整个类,描述Controller的作用
@ApiOperation:描述一个类的一个方法,或者说一个接口
@ApiParam:单个参数描述

@ApiModel:用对象来接收参数
@ApiProperty:用对象接收参数时,描述对象的一个字段

其它若干

@ApiResponse:HTTP响应其中1个描述
@ApiResponses:HTTP响应整体描述

@ApiClass
@ApiError
@ApiErrors

@ApiParamImplicit
@ApiParamsImplicit

@ApiOperation(value = "获得用户列表", notes = "列表信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@RequestMapping(value = "list", method = RequestMethod.POST)
public Result<User> list(
@ApiParam(value = "分类ID", required = true) @RequestParam Long categoryId,
@ApiParam(value = "token", required = true) @RequestParam String token) {
Result<User> result = new Result<User>();
User user = new User();
result.setData(user);
return result;
}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: