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

时间:2025-03-20 07:07:58

   

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


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                 /*Controller层的包地址*/
                .apis((""))
                /*接口请求地址前缀rest
                 *  比如 @RequestMapping(value = "/rest/article/{id}")     
                    可以写 /.* 但是要写明 接口发送post或get 或等等     
                 *
                 */ 
                 .paths(("/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) {
        ("1111");
    }

}