Spring Boot OpenAPI 3 - 如何传递分页细节?
Spring Boot OpenAPI 3 - How to pass the Pagination Details?
我希望通过查看 https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/ and https://techsparx.com/software-development/openapi/spring-boot-rest-api-docs.html 来开发 Spring Boot + OpenAPI 3 示例。在此示例中,我希望通过添加 springdoc-openapi-ui
获得的 Swagger UI 传递分页详细信息。
我需要做什么 Spring 引导配置才能支持自定义分页。?
在方法上添加@PageableAsQueryParam注解
并将 springdoc-openapi-data-rest 添加为依赖项
他们有不止一种可能性,最简单和最快的是如果只想启用 spring 可分页类型的支持,您可以使用以下方式启用它:
SpringDocUtils.getConfig().replaceWithClass(org.springframework.data.domain.Pageable.class,
org.springdoc.core.converters.models.Pageable.class);
或者,使用 Pageable 类型的项目也可以将以下依赖项与 springdoc-openapi-ui 依赖项一起添加。此依赖项还支持 spring-data-rest 类型:@RepositoryRestResource 和 QuerydslPredicate 注释。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.5.6</version>
</dependency>
并在控制器方法的 Pageable 对象上添加 @ParameterObject。
@GetMapping("/books")
public ResponseEntity<List<BookDTO>> getBooks(@ParameterObject Pageable pageable)
“自 springdoc-openapi v1.6.0 起,out-of-the 框支持 spring-data-commons 的 Pageable。为此,您必须将 @ParameterObject
注释与 Pageable
类型。” - Source
假设您使用的是 springdoc-openapi v1.6.0 或 grater,您可以这样做:
@GetMapping("/foo")
public Page<Foo> getFoo(@ParameterObject Pageable pageable) {
// do something
}
我希望通过查看 https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/ and https://techsparx.com/software-development/openapi/spring-boot-rest-api-docs.html 来开发 Spring Boot + OpenAPI 3 示例。在此示例中,我希望通过添加 springdoc-openapi-ui
获得的 Swagger UI 传递分页详细信息。
我需要做什么 Spring 引导配置才能支持自定义分页。?
在方法上添加@PageableAsQueryParam注解 并将 springdoc-openapi-data-rest 添加为依赖项
他们有不止一种可能性,最简单和最快的是如果只想启用 spring 可分页类型的支持,您可以使用以下方式启用它:
SpringDocUtils.getConfig().replaceWithClass(org.springframework.data.domain.Pageable.class,
org.springdoc.core.converters.models.Pageable.class);
或者,使用 Pageable 类型的项目也可以将以下依赖项与 springdoc-openapi-ui 依赖项一起添加。此依赖项还支持 spring-data-rest 类型:@RepositoryRestResource 和 QuerydslPredicate 注释。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.5.6</version>
</dependency>
并在控制器方法的 Pageable 对象上添加 @ParameterObject。
@GetMapping("/books")
public ResponseEntity<List<BookDTO>> getBooks(@ParameterObject Pageable pageable)
“自 springdoc-openapi v1.6.0 起,out-of-the 框支持 spring-data-commons 的 Pageable。为此,您必须将 @ParameterObject
注释与 Pageable
类型。” - Source
假设您使用的是 springdoc-openapi v1.6.0 或 grater,您可以这样做:
@GetMapping("/foo")
public Page<Foo> getFoo(@ParameterObject Pageable pageable) {
// do something
}