当前位置:   article > 正文

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

swagger没有页面

maven

io.springfox

springfox-swagger2

2.6.1

io.springfox

springfox-swagger-ui

2.6.1

允许访问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 fansList = this.fansMapper.selectFansList(userId);

PageInfo pageInfo = new PageInfo<>(fansList);

map.put("list",pageInfo.getList()); return new JsonResult(ResultCode.SUCCESS,map);}--------------------- 作者:高小川 来源:CSDN 原文:https://blog.csdn.net/u013128651/article/details/78864876 版权声明:本文为博主原创文章,转载请附上博文链接!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/897676?site
推荐阅读
相关标签
  

闽ICP备14008679号