Criteria criteria = Criteria.where("tag"); String[] tags = tag.split(","); for (int i = 0; i < tags.length; i++) { criteria.regex("/*" + tags[i] +"/*", "i"); } Query query = Query.query(criteria); Query query2 = Query.query(criteria); int count = mongoTemplate.find(query2, ThingBean.class).size(); if(SORTORDER.equals(sortOrder)){ query.with(new Sort(Direction.DESC , sortType)); }else{ query.with(new Sort(Direction.ASC , sortType)); } int skip = (pageIndex- 1) * pageSize; /** * 从那条记录开始 */ query.skip(skip); /** * 取多少条记录 */ query.limit(pageSize); List<ThingBean> thingBeans = mongoTemplate.find(query, ThingBean.class); PageBean pageBean = new PageBean(); pageBean.setData(thingBeans); pageBean.setPageIndex(pageIndex); pageBean.setPageSize(pageSize); pageBean.setCount(count); result.setCode("200"); result.setData(pageBean); List<TagBean> tagCount = new ArrayList<TagBean>(); for (int i = 0; i < tags.length; i++) { List<TagBean> tagBean = tagRepository.findByTagNameAndTenantId(tags[i], tenantId); if(tagBean.size() == 1){ tagCount.add(tagBean.get(0)); } } for (int i = 0; i < tagCount.size(); i++) { tagCount.get(i).setCount(tagCount.get(i).getCount()+1); tagRepository.save(tagCount.get(i)); } return result;
springboot+mongoTemplate分页查询
猜你喜欢
转载自blog.csdn.net/qq_37497275/article/details/80538987
今日推荐
周排行