Spring boot集成Swagger2,解决页面不显示的问题

Posted wuyb123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring boot集成Swagger2,解决页面不显示的问题相关的知识,希望对你有一定的参考价值。

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", "[email protected]"))
//版本号
.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,解决页面不显示的问题的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot 入门:集成 swagger2

Spring boot - 集成Swagger2

Spring boot集成swagger2

spring boot集成Swagger2

spring boot 1.5.4 集成Swagger2构建Restful API(十八)

spring boot集成swagger2