代码修改
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package org.nl.mongodb;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public class Test {
|
||||
|
||||
|
||||
public Page test2(Integer currentPage, Integer pageSize, Long loanApplyId) {
|
||||
/* //创建查询对象
|
||||
Query query = new Query();
|
||||
//设置起始数
|
||||
query.skip((currentPage - 1) * pageSize);
|
||||
//设置查询条数
|
||||
query.limit(pageSize);
|
||||
Criteria criteria = new Criteria();
|
||||
criteria.where("loanApplyId").is(loanApplyId);
|
||||
//查询当前页数据集合
|
||||
List<ApplyLog> ApplyLogList = mongoTemplate.find(query, ApplyLog.class);
|
||||
//查询总记录数
|
||||
int count = (int) mongoTemplate.count(query, ApplyLog.class);
|
||||
//创建分页实体对象
|
||||
Page<ApplyLog> page = new Page<>();
|
||||
//添加每页的集合、数据总条数、总页数
|
||||
page.setRecords(ApplyLogList);
|
||||
page.setSize(count);
|
||||
page.setTotal(count % pageSize == 0 ? 1 : count / pageSize + 1);
|
||||
return page;
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
/* int pageNo = 1;
|
||||
int pageSize = 10;
|
||||
|
||||
// limit限定查询2条
|
||||
Query query = Query.query(Criteria.where("user").is("一灰灰blog").and("a").is("b").and("")).with(Sort.by("age")).limit(2);
|
||||
//Query query = Query.query(Criteria.where("user").is("一灰灰blog")).with(Sort.by("age")).limit(2);
|
||||
// Pageable pageable = PageRequest.of(page,size);
|
||||
List<Map> result = mongoTemplate.find(query, Map.class, "logdb");
|
||||
System.out.println("query: " + query + " | limitPageQuery " + result);
|
||||
|
||||
|
||||
// skip()方法来跳过指定数量的数据
|
||||
query = Query.query(Criteria.where("user").is("一灰灰blog")).with(Sort.by("age")).skip(2);
|
||||
result = mongoTemplate.find(query, Map.class, "logdb");
|
||||
System.out.println("query: " + query + " | skipPageQuery " + result);
|
||||
|
||||
|
||||
|
||||
Query query = new Query(new Criteria());
|
||||
query.with(Sort.by(Sort.Direction.DESC, "time"));
|
||||
mongoUtil.start(2, 2, query);
|
||||
List<Teacher> teachers = mongoTemplate.find(query, Teacher.class);
|
||||
long count = mongoTemplate.count(query, Teacher.class);
|
||||
PageHelper pageHelper = mongoUtil.pageHelper(count, teachers);*/
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user