当前位置: 首页 > 工具软件 > Html2Article > 使用案例 >

swagger2 接口文档扩展swagger-bootstrap-ui 访问doc.html 404问题,

简宏义
2023-12-01

   

.paths(PathSelectors.any()) 这个会导致404 不知道为什么
.paths(PathSelectors.regex("/.*")) 接口前缀
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                 /*Controller层的包地址*/
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.Controller"))
                /*接口请求地址前缀rest
                 *  比如 @RequestMapping(value = "/rest/article/{id}")     
                    可以写 /.* 但是要写明 接口发送post或get 或等等     
                 *
                 */ 
                 .paths(PathSelectors.regex("/rest/.*"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger-bootstrap-ui RESTful APIs")
                .description("swagger-bootstrap-ui")
                .termsOfServiceUrl("http://localhost:8080/")
                .contact("TongLing")
                .version("1.0")
                .build();
    }

}
@RestController
public class ArticleRestController {
    @ApiOperation(value = "根据id查询学生信息", notes = "查询数据库中某个的学生信息")
    @ApiImplicitParam(name = "id", value = "学生ID", paramType = "path", required = true, dataType = "Integer")
    @RequestMapping(value = "/rest/article/{id}", method = GET, produces = "application/json")
    public void getStudent(@PathVariable int id) {
        System.out.println("1111");
    }

}

 

 类似资料: