Springboot | SpringBoot 微服务整合Swagger生成API文档
2018-02-12 18:23
1011 查看
关于swagger的优点就不描述了,直接来看一下使用示例:
1)首先引入swagger依赖:
<!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency>
2)Swagger配置:
/** * Created by zhangshukang on 2017/11/9. */ @Configuration @EnableSwagger2 public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.iyb.ak")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("mars组件 RESTful APIs") .description("mars组件api接口文档") .version("1.0") .build(); } }
3)对应的controller如下:
@RestController @Slf4j @RequestMapping(value = "/content") @Api(value = "ContentsController", description = "内容接口") public class ContentsController { @Autowired ContentsService contentsService; @ApiOperation(value = "查询内容", notes = "根据id查询内容") @RequestMapping(value ="/{id}",method = RequestMethod.GET) public Callable<Contents> getContentById(@PathVariable("id") Integer id) throws Exception { Contents content = new Contents(); return ()->Arrays.asList(content).get(0); } @ApiOperation(value = "修改content", notes = "根据content对象创建角色") @ApiImplicitParam(name = "修改content", value = "content详细实体", required = true, dataType = "content") @ApiResponses({ @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对", response = MessageVo.class) }) @RequestMapping(method= RequestMethod.PUT) public Contents updateContent(@RequestBody Contents contents){ return contentsService.updateByPrimaryKey(contents); } }
4)swagger api 访问如下:
相关文章推荐
- spring-boot整合swagger生成在线api文档
- Spring Boot如何让Web API自动生成文档,并解决swagger-annotations的API注解description属性废弃的问题
- SpringBoot&Swagger构建REST API并生成API文档
- SpringBoot:番外篇SpringBoot+Swagger生成可视图的API文档
- SpringBoot + mybatis + Swagger快速构建REST API并生成优美的API文档
- 使用Spring Boot&Swagger快速构建REST API并生成优美的API文档
- SwaggerUI自动生成API文档(SwaggerUI+SpringBoot)
- SpringCloud SpringBoot mybatis 分布式微服务(二十九)Restdoc生成api文档
- Swagger自动接口文档生成框架————springboot整合swagger总结
- 使用 SpringBoot + Swagger 生成接口 API 文档
- SpringCloud SpringBoot mybatis 分布式微服务(二十三)Restdoc生成api文档
- Spring boot结合swagger自动生成api文档
- Swagger2 生成 Spring Boot API 文档
- spring boot 中使用swagger 来自动生成接口文档
- 使用Swagger在SpringBoot项目中管理API文档(使用Oauth2)
- spring Swagger生成API文档
- SpringMVC+Swagger UI生成可视图的API文档(详细图解)
- 基于Nginx+Spring Boot+Swagger的api文档实践
- 在Spring中使用Springfox和swagger生成restful风格的API文档
- spring集成swagger生成api文档的丢弃接口添加删除线效果