1
0

feat: 增加排序

This commit is contained in:
2024-12-22 13:21:35 +08:00
parent afb87d0c12
commit c07a524d64
2 changed files with 4 additions and 3 deletions

View File

@@ -44,7 +44,7 @@ class ChapterController {
): PageResponse<ViewItem> {
val pageable = chapterRepository.findAll({ root, _, builder ->
builder.equal(root.get<Book>("book").get<String>("bookId"), bookId)
}, PageRequest.of(0.coerceAtLeast(page - 1), size))
}, PageRequest.of(0.coerceAtLeast(page - 1), size).withSort(Sort.by(Sort.Direction.ASC, "sequence")))
return PageResponse(
pageable.content.map { ViewItem(it) },
pageable.totalElements,

View File

@@ -10,6 +10,7 @@ import jakarta.annotation.Resource
import jakarta.transaction.Transactional
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
@@ -33,11 +34,11 @@ class LineController {
fun list(
@PathVariable("chapterId") chapterId: String,
@RequestParam("page", defaultValue = "1") page: Int,
@RequestParam("size", defaultValue = "10") size: Int
@RequestParam("size", defaultValue = "10") size: Int,
): PageResponse<ViewItem> {
val pageable = lineRepository.findAll({ root, _, builder ->
builder.equal(root.get<Chapter>("chapter").get<String>("chapterId"), chapterId)
}, PageRequest.of(0.coerceAtLeast(page - 1), size))
}, PageRequest.of(0.coerceAtLeast(page - 1), size).withSort(Sort.by(Sort.Direction.ASC, "sequence")))
return PageResponse(
pageable.content.map { ViewItem(it) },
pageable.totalElements,