pom文件添加依赖

swagger与spring使用的方式

Swagger配置类

swagger与spring使用的方式

开启Swagger

在启动类上添加注解

swagger与spring使用的方式

swagger2注解介绍:

swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等,如:
@ApiIgnore:使用注解忽略该API,不会参与文档生成
@ApiOperation:描述该api,如: @ApiOperation(value=”创建用户”, notes=”根据User对象创建用户”)
请求方法:@RequestMapping(value = “user”, method = RequestMethod.POST)
参数x信息:@ApiImplicitParam(name = “user”, value = “用户详细实体user”, required = true, dataType = “User”)
@Api:修饰整个类,描述Controller的作用
@ApiParam:单个参数描述
@ApiModel:用对象来接收参数
@ApiResponses:HTTP响应整体描述
@ApiProperty:用对象接收参数时,描述对象的一个字段
 

最后启动项目

访问

           http://localhost:8080/swagger-ui.html#/

就可以看到

swagger与spring使用的方式

相关文章: