继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

SpringMVC 集成 swagger2

纯情的慕哥
关注TA
已关注
手记 22
粉丝 5
获赞 8

引入jar

<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>

写配置文件

@Configuration
@EnableSwagger2
public class Swagger {
    @Bean
    public Docket buildDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//调用下面apiInfo()方法
                .select()
                //Controller所在路径
                .apis(RequestHandlerSelectors.basePackage("com.young.web"))
                .paths(PathSelectors.any())
                .build();

    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("srpingmvc结合swagger2构建Restful API")
//                http://localhost:8080/swagger-ui.html
                .termsOfServiceUrl("http://localhost")
                .version("0.0.1")
                .description("API接口")
                .build();

    }
}

spring*.xml配置

<!--启动swagger2 -->
    <bean class="com.young.util.Swagger"/>

编写接口文档

 @GetMapping("/getshoplist")
 @ApiOperation("获取店铺列表")
 private Map<String, Object> getShopList(HttpServletRequest request) {
    ……
}

访问

端口后面有系统名则需要加上

http://localhost:8080/swagger-ui.html
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP