默认id逆序
This commit is contained in:
@@ -112,7 +112,7 @@ fun order(orders: Map<String, OrderType>?): Sort {
|
|||||||
orderList.add(Sort.Order(Sort.Direction.valueOf(it.value.name), it.key))
|
orderList.add(Sort.Order(Sort.Direction.valueOf(it.value.name), it.key))
|
||||||
}
|
}
|
||||||
return if (orderList.size == 0)
|
return if (orderList.size == 0)
|
||||||
Sort.by("_id")
|
Sort.by(Sort.Direction.DESC, "_id")
|
||||||
else
|
else
|
||||||
Sort.by(orderList)
|
Sort.by(orderList)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ open class MongoGenericQuery<TView>(
|
|||||||
}
|
}
|
||||||
query.select(fields.toTypedArray())
|
query.select(fields.toTypedArray())
|
||||||
query.where(param.parameters, this.clazz!!)
|
query.where(param.parameters, this.clazz!!)
|
||||||
query.with(order(param.orderBy))
|
query.with(order(param.orders))
|
||||||
query.skip(param.index).limit(param.size)
|
query.skip(param.index).limit(param.size)
|
||||||
result.data = this.template.find(query, this.clazz!!, this.collection)
|
result.data = this.template.find(query, this.clazz!!, this.collection)
|
||||||
result
|
result
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ open class MongoQuery(var template: MongoTemplate, var logger: ILogger? = null)
|
|||||||
}
|
}
|
||||||
query.select(fields.toTypedArray())
|
query.select(fields.toTypedArray())
|
||||||
query.where(param.parameters, clazz)
|
query.where(param.parameters, clazz)
|
||||||
query.with(order(param.orderBy))
|
query.with(order(param.orders))
|
||||||
query.skip(param.index).limit(param.size)
|
query.skip(param.index).limit(param.size)
|
||||||
result.data = this.template.find(query, clazz, this.collection(clazz))
|
result.data = this.template.find(query, clazz, this.collection(clazz))
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ data class Params(var page: Int = 1, var size: Int = 10) {
|
|||||||
/**
|
/**
|
||||||
* 排序条件。
|
* 排序条件。
|
||||||
*/
|
*/
|
||||||
var orderBy: MutableMap<String, OrderType> = hashMapOf()
|
var orders: MutableMap<String, OrderType> = hashMapOf()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条件。
|
* 查询条件。
|
||||||
@@ -38,7 +38,7 @@ data class Params(var page: Int = 1, var size: Int = 10) {
|
|||||||
* 添加排序条件
|
* 添加排序条件
|
||||||
*/
|
*/
|
||||||
fun addOrderBy(field: String, type: OrderType = OrderType.ASC): Params {
|
fun addOrderBy(field: String, type: OrderType = OrderType.ASC): Params {
|
||||||
orderBy[field] = type
|
orders[field] = type
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user