标签:created 版权 登录 handler 设置 user ons 不显示 开放
maven
<!-- swagger -->
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.6.1</version>
</dependency>
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>2.6.1</version>
</dependency>
允许访问Swagger ui静态页面
/**
 * Created by gaomin on 2017/10/20.
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
/**
 * 对外开放的接口 接口文档生成
 * Created by gaomin on 2017/12/14.
 */
@EnableSwagger2
@Configuration
public class Swagger2 {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为controller包路径
                .apis(RequestHandlerSelectors.basePackage("com.common.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //构建 api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring Boot使用 Swagger2 构建RestFul API")
                //创建人
                .contact(new Contact("小川", "http://localhost:8764/swagger-ui.html", "1598078574@qq.com"))
                //版本号
                .version("1.0")
                //描述
                .description("跑圈模块接口文档")
                .build();
    }
}
@ApiOperation(value="粉丝列表分页接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "当前页数1开始",  dataType = "int",paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "每页的大小",  dataType = "int",paramType = "query"),
        @ApiImplicitParam(name = "userId", value = "当前登录的用户id", dataType = "int",paramType = "query")
})
@RequestMapping(value = "/getFansList" , method = RequestMethod.GET)
public JsonResult getFansPage(@RequestParam(value = "page", required = false, defaultValue = "1") int page,
                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
                              int userId) {
    Map map = new HashMap();
    PageHelper.startPage(page, pageSize);//设置分页参数
    List<Fans> fansList = this.fansMapper.selectFansList(userId);
    PageInfo<Fans> pageInfo = new PageInfo<>(fansList);
    map.put("list",pageInfo.getList());
    return new JsonResult(ResultCode.SUCCESS,map);
}
--------------------- 
作者:高小川 
来源:CSDN 
原文:https://blog.csdn.net/u013128651/article/details/78864876 
版权声明:本文为博主原创文章,转载请附上博文链接!
Spring boot集成Swagger2,解决页面不显示的问题
标签:created 版权 登录 handler 设置 user ons 不显示 开放
原文地址:https://www.cnblogs.com/wuyb123/p/10459376.html