Spring Boot整合Swagger-Bootstrap-UI

本文主要介绍了swagger-bootstrap-ui 结合springboot 的使用方法,相比于传统的有一些风格上面的改进。
废话不多说,说重点。
springBoot 三板斧:

  1. pom 文件加依赖
  2. 加上对应的注解
  3. 编代码,启动项目
    第一步:引入对应的依赖
        
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger2artifactId>
            <version>2.7.0version>
        dependency>

        <dependency>
            <groupId>com.github.xiaoymingroupId>
            <artifactId>swagger-bootstrap-uiartifactId>
            <version>1.9.3version>
        dependency>

第二步:配置swagger 配置类

package com.hu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
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;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
     
    @Bean
    public Docket createRestApi() {
     
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
     
        return new ApiInfoBuilder()
                .title("我ོ自ོ己ོ的ོ接ོ口ོ文ོ档ོ")
                .description("swagger 接ོ口ོ文ོ档ོ ")
                .version("v1.0.0")
                .build();
    }

}



第ོ三ོ步ོ:写ོ入ོ对ོ应ོ的ོ注ོ解ོ配ོ置ོ信ོ息ོ

@RestController
@Api(tags = "学ོ生ོ信ོ息ོ相ོ关ོ的ོ接ོ口ོ")
public class TestController {
    @ApiOperation(value="得ོ到ོ学ོ生ོ信ོ息ོ",notes="获ོ得ོ学ོ生ོ信ོ息ོ接ོ口ོ")
    @GetMapping("/test")
    public Student getStudent(){
        Student student = new Student();
        student.setAge(18);
        student.setName("测ོ试ོ");
        return student;
    }
}

启动项目就可以看见对应的界面了:http://localhost:8080/doc.html
Spring Boot整合Swagger-Bootstrap-UI_第1张图片
码字不易,谢谢!

你可能感兴趣的:(spring,boot,swagger2,bootstrap,java)