Created
October 4, 2022 11:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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