feat: 增加排序
This commit is contained in:
@@ -44,7 +44,7 @@ class ChapterController {
|
|||||||
): PageResponse<ViewItem> {
|
): PageResponse<ViewItem> {
|
||||||
val pageable = chapterRepository.findAll({ root, _, builder ->
|
val pageable = chapterRepository.findAll({ root, _, builder ->
|
||||||
builder.equal(root.get<Book>("book").get<String>("bookId"), bookId)
|
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(
|
return PageResponse(
|
||||||
pageable.content.map { ViewItem(it) },
|
pageable.content.map { ViewItem(it) },
|
||||||
pageable.totalElements,
|
pageable.totalElements,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import jakarta.annotation.Resource
|
|||||||
import jakarta.transaction.Transactional
|
import jakarta.transaction.Transactional
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.data.domain.PageRequest
|
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.GetMapping
|
||||||
import org.springframework.web.bind.annotation.PathVariable
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
@@ -33,11 +34,11 @@ class LineController {
|
|||||||
fun list(
|
fun list(
|
||||||
@PathVariable("chapterId") chapterId: String,
|
@PathVariable("chapterId") chapterId: String,
|
||||||
@RequestParam("page", defaultValue = "1") page: Int,
|
@RequestParam("page", defaultValue = "1") page: Int,
|
||||||
@RequestParam("size", defaultValue = "10") size: Int
|
@RequestParam("size", defaultValue = "10") size: Int,
|
||||||
): PageResponse<ViewItem> {
|
): PageResponse<ViewItem> {
|
||||||
val pageable = lineRepository.findAll({ root, _, builder ->
|
val pageable = lineRepository.findAll({ root, _, builder ->
|
||||||
builder.equal(root.get<Chapter>("chapter").get<String>("chapterId"), chapterId)
|
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(
|
return PageResponse(
|
||||||
pageable.content.map { ViewItem(it) },
|
pageable.content.map { ViewItem(it) },
|
||||||
pageable.totalElements,
|
pageable.totalElements,
|
||||||
|
|||||||
Reference in New Issue
Block a user