美文网首页springboot
springboot swagger ui创建resultful

springboot swagger ui创建resultful

作者: rainbowz | 来源:发表于2018-12-28 23:17 被阅读3次

    springboot 2.0.1版本

    SwaggerConfig
    
    package com.demo.config;
    
    import org.springframework.context.annotation.Bean;
    import io.swagger.annotations.ApiOperation;
    import org.springframework.context.annotation.Configuration;
    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 SwaggerConfig {
    
        @Bean
        public Docket swaggerSpringMvcPlugin() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    // 自行修改为自己的包路径
                    .apis(RequestHandlerSelectors.basePackage("com.demo.controller"))
                    .paths(PathSelectors.any())
                    .build();
    
        }
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("api文档")
                    .description("restfun 风格接口")
                    //服务条款网址
                    //.termsOfServiceUrl("http://blog.csdn.net/forezp")
                    .version("1.0")
                    //.contact(new Contact("帅呆了", "url", "email"))
                    .build();
        }
    }
    
    
    pom依赖
    
    <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.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    
    @EnableAutoConfiguration
    @SpringBootApplication
    @MapperScan("com.demo.dao")
    public class DemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    
    }
    

    控制层和上篇文章一样,时间关系不说了 浏览器;里面访问
    http://localhost:8788/swagger-ui.html

    图片.png

    点击Stu Controller


    到此一个简单swagger ui restful完成了
    Thanks

    相关文章

      网友评论

        本文标题:springboot swagger ui创建resultful

        本文链接:https://www.haomeiwen.com/subject/zvyylqtx.html