diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/ChapterController.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/ChapterController.kt index 26a9144..a62970f 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/ChapterController.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/ChapterController.kt @@ -44,7 +44,7 @@ class ChapterController { ): PageResponse { val pageable = chapterRepository.findAll({ root, _, builder -> builder.equal(root.get("book").get("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, diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt index f511a96..10eac0c 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/controller/LineController.kt @@ -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 { val pageable = lineRepository.findAll({ root, _, builder -> builder.equal(root.get("chapter").get("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,