Skip to content

Instantly share code, notes, and snippets.

@90K2
Created October 4, 2022 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 90K2/0cc43ee4a349b1e5d99716e0dd3f41d5 to your computer and use it in GitHub Desktop.
Save 90K2/0cc43ee4a349b1e5d99716e0dd3f41d5 to your computer and use it in GitHub Desktop.
Spring pageable extension. Fixed current page number, reduced pageable and sorting extra fields, map function for content transformation saved
import org.springframework.data.domain.Page
class PageLite<T>(page: Page<T>) {
var content: List<T> = page.content
var pageable = PageableLite(
number = page.pageable.pageNumber + 1,
size = page.pageable.pageSize,
total = page.totalElements
)
fun <R> map(transform: (T) -> R) = PageableImpl(
content = this.content.map { transform(it) }.toList(),
pageable = this.pageable
)
}
data class PageableLite(
val number: Int,
val size: Int,
val total: Long
)
data class PageableImpl<T>(
val content: List<T>,
val pageable: PageableLite
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment