首页 > 编程知识 正文

mongotemplate 查listmongoTemplate查询,圆通物流查单查询

时间:2023-05-05 07:23:50 阅读:198311 作者:3632

//设置分页

Integer pageSize = po.getPageSize();

Integer startRows = (po.getPage() - 1) * pageSize;

//模糊查询

Criteria criteria = new Criteria();

if (!StringUtils.isEmpty(po.getKeyword())){

Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);

criteria = Criteria.where("teacherName").regex(pattern);

}

Aggregation customerAgg = Aggregation.newAggregation(

Aggregation.project("teacherId", "messageId", "teacherName"), //相当于select

Aggregation.match(criteria), //查询条件相当于where

Aggregation

.group("teacherId").first("teacherId").as("teacherId") //分组

.first("messageId").as("id") //as起别名对应实体字段

.first("teacherName").as("name")

.count().as("replyNum"),//组内统计数

Aggregation.sort(Sort.by(Sort.Order.asc("messageId"))),//排序

Aggregation.sort(Sort.by(Sort.Order.asc("messageId"))),

Aggregation.skip(startRows),

Aggregation.limit(pageSize)

);

AggregationResults aggregate = mongoTemplate.aggregate(customerAgg, TableConstant.USER_TALK_INFOR, AnswerQueVo.class);

List list = aggregate.getMappedResults();

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。