jeesite中集成Swagger2 三步
2017-11-22 09:44
218 查看
jeesite中集成Swagger2 三步
前后端分离时使用swagger来进行接口文档的管理还是很不错的选择。这里记录一下如何在java开源开发平台jeesite上集成swagger2。一、导入依赖
`<!-- 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> `
二、配置类编写
`
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * * @author houzhongfei * */ @EnableWebMvc @EnableSwagger2 @ComponentScan(basePackages = {"com.ms.plat.modules.api"}) @Configuration public class SwaggerConfig extends WebMvcConfigurationSupport{ @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("project-java-api") .select() .apis(RequestHandlerSelectors.basePackage("com.ms.plat.modules.api")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("project API") .termsOfServiceUrl("http://localhost:8181/project/swagger-ui.html") .contact("JAVA") .version("1.0") .build(); } }
`
三、在接口中增加swagger相关注解
`package com.ms.plat.modules.api.admin.logsmanage; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.ms.plat.common.web.BaseController; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; /** * * @author houzhongfei * */ @Controller //@Api(value = "EmailLog API Controller(here is @Api value)", tags = "测试接口(here is @Api tags)") public class EmailLog extends BaseController { @ApiOperation(value = "here is @ApiOperation value",tags = "测试接口2(here is @Api tags)", notes = "here is @ApiOperation notes") @RequestMapping(value = "hello/{name}", method = RequestMethod.POST) @ApiResponses({ @ApiResponse(code = 400, message = "Invalid Order1111") }) public @ResponseBody String helloSwagger( @ApiParam(name = "name", value = "参数名字(here is @ApiParam value)", required = true) @PathVariable String name) { return "hello" + name; } }
`
效果:
相关文章推荐
- Swagger2与Spring mvc集成
- jeesite 学习笔记
- SpringBoot集成Swagger2
- SpringMvc 3分钟集成swagger2
- 从0开始学习SpringCould(6)--SpringBoot 集成swagger2
- Spring boot集成Swagger2,解决页面不显示的问题
- SpringMVC集成springfox-swagger2构建restful API
- eclipse-jee集成tomcat插件 自动部署
- JeeSite基础知识(一)
- SpringBoot集成Swagger2,以及Swagger2常用API
- Spring Boot实战:集成Swagger2
- Jeesite中shiro的用法讲解
- SpringBoot精藏(九)SpringBoot集成swagger2
- Jeesite-导入导出源码跟踪分析(导出)
- 企业分布式微服务云SpringCloud SpringBoot mybatis (二十五)集成swagger2构建Restful API
- SpringMVC集成Swagger2详解
- Jeesite4.0 Missing artifact com.jeesite:jeesite-module-core:jar:4.0-SNAPSHOT
- jeesite快速开发平台(四)----数据库各表一览
- GitHub 集成在Windows Azure Web Site中
- Spring mvc Swagger2 API 集成记录