2019-12-31 Api接口文档管理工具 SwaggerUI

Swagger 官方文档: https://swagger.io/。

导入pom依赖
 
    
        io.springfox
        springfox-swagger2
        2.4.0
    

    
        io.springfox
        springfox-swagger-ui
        2.4.0
    
新建一个配置类(SwaggerConfig)
@Configuration
@EnableWebMvc
@EnableSwagger2
public class Swagger2Config extends WebMvcConfigurerAdapter {

    @Bean
    public Docket buildDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo());
        docket = docket.select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
        return docket;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
                .title("RestApi docs")
                .termsOfServiceUrl("http://www.github.com/kongchen/swagger-maven-plugin")
                .build();
    }
}
Controller类中注解
@Api(tags = "hello测试接口")
@RequestMapping("/test")
@Controller
public class HelloWorldController {

    @Autowired
    private HelloWorld helloWorld;

    @ApiOperation(value = "返回字符串 hello", notes = "可以注解接口参数信息")
    @GetMapping("/hello")  //建议:请求类型写清楚(get/post),以便接口文档中可以单击打开
    @ResponseBody
    public String hello(){
       return helloWorld.helloWorld();
    }
}

建议:请求类型写清楚(get/post),以便接口文档中可以单击打开

输出本地URL和端口 进入Swagger页面
2019-12-31 Api接口文档管理工具 SwaggerUI_第1张图片
Swagger页面

你可能感兴趣的:(2019-12-31 Api接口文档管理工具 SwaggerUI)