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

阿里云双12感恩回馈,云产品冰点价】云服务器89元/年,这里有专享低价

[链接] https://www.aliyun.com/minisite/goods?userCode=kki5ownb

 

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); } 

 

 

 

 

 

你可能感兴趣的:(Spring,Boot,Spring,cloud,分布式)