2 回答
TA贡献1811条经验 获得超5个赞
//One or two records from your collection
const data = [{
name: 'abc',
place: 'US',
zone: 'Pacific'
}, {
name: 'xyz',
place: 'PK',
zone: 'Asia'
}, ]
const fields = Object.keys(data[0]);
console.log("Fields in collection: ",fields);
const sortBy = fields[0];
console.log("Sort By: ", sortBy);
//const sort = new Sort("DESC".equalsIgnoreCase(filter.getSortOrder()) ? //Sort.Direction.DESC : Sort.Direction.ASC, sortBy);
//PageRequest pageRequest = = PageRequest.of(filter.getPageNumber(), //filter.getPageSize(), sort);
//Page < Offer > st = new PageImpl < > //(mongoTemplate.find(query.with(pageRequest), Offer.class), pageRequest, //pageCount);
sort 参数是一个value(字符串类型),在其上执行排序,您不能传递需要进一步评估(在您的情况下)以获取值的字符串。而是直接将您的值保存到您的sortBy变量中,然后传递sortBy给您的查询。
添加回答
举报