我有一个带有 REST 控制器的 SpringBoot 应用程序,我需要按实体属性(包括地图值)进行排序。
这是我的实体类:
@Document
data class Event(
@Id
val id: CompoundId,
@Indexed
val timestamp: Instant,
val description: String,
val values: Map<String, Any> = HashMap()
)
我的 REST 控制器 GET:
@GetMapping("/")
fun getEvents(
@PageableDefault(sort = ["timestamp"], direction = Sort.Direction.ASC)
pageable: Pageable?
): Collection<Event> = mongoRepository.find(pageable)
另外,我使用 MongoDB:
override fun find(pageable: Pageable?): Collection<Event> {
Query().apply {
pageable?.let { with(pageable) }
return mongoTemplate.find(this, Event::class.java)
}
}
我正在尝试提出这样的请求:http://localhost:8080?sort=values,DESC我看到顺序已更改,但我无法理解它对哪些参数进行了排序。
是否可以按地图参数排序Pageable,例如http://localhost:8080?sort=values.someKeyInTheMap,DESC?