本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.find()
方法的一些代码示例,展示了MongoTemplate.find()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.find()
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:find
暂无
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public <T> List<T> find(Query query, Class<T> entityClass) {
return find(query, entityClass, operations.determineCollectionName(entityClass));
}
代码示例来源:origin: kaaproject/kaa
protected List<T> find(Query query) {
return mongoTemplate.find(query, getDocumentClass());
}
代码示例来源:origin: yu199195/hmily
@Override
public List<HmilyTransaction> listAllByDelay(final Date date) {
Query query = new Query();
query.addCriteria(Criteria.where("lastTime").lt(date));
final List<MongoAdapter> mongoBeans =
template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoBeans)) {
return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
}
return Collections.emptyList();
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Retrieve and remove all documents matching the given {@code query} by calling {@link #find(Query, Class, String)}
* and {@link #remove(Query, Class, String)}, whereas the {@link Query} for {@link #remove(Query, Class, String)} is
* constructed out of the find result.
*
* @param collectionName
* @param query
* @param entityClass
* @return
*/
protected <T> List<T> doFindAndDelete(String collectionName, Query query, Class<T> entityClass) {
List<T> result = find(query, entityClass, collectionName);
if (!CollectionUtils.isEmpty(result)) {
Query byIdInQuery = operations.getByIdInQuery(result);
remove(byIdInQuery, entityClass, collectionName);
}
return result;
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Nullable
@Override
public <T> T findOne(Query query, Class<T> entityClass, String collectionName) {
Assert.notNull(query, "Query must not be null!");
Assert.notNull(entityClass, "EntityClass must not be null!");
Assert.notNull(collectionName, "CollectionName must not be null!");
if (ObjectUtils.isEmpty(query.getSortObject()) && !query.getCollation().isPresent()) {
return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass);
} else {
query.limit(1);
List<T> results = find(query, entityClass, collectionName);
return results.isEmpty() ? null : results.get(0);
}
}
代码示例来源:origin: yu199195/myth
@Override
public List<MythTransaction> listAllByDelay(final Date date) {
Query query = new Query();
query.addCriteria(Criteria.where("lastTime").lt(date))
.addCriteria(Criteria.where("status").is(MythStatusEnum.BEGIN.getCode()));
final List<MongoAdapter> mongoBeans = template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoBeans)) {
return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
}
return Collections.emptyList();
}
代码示例来源:origin: yu199195/Raincat
@Override
public List<TransactionRecover> listAll() {
Query query = new Query();
query.addCriteria(new Criteria("status")
.in(TransactionStatusEnum.BEGIN.getCode(),
TransactionStatusEnum.FAILURE.getCode(),
TransactionStatusEnum.ROLLBACK.getCode()));
final List<MongoAdapter> mongoAdapterList =
template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoAdapterList)) {
return mongoAdapterList.stream().map(this::buildByCache).collect(Collectors.toList());
}
return null;
}
代码示例来源:origin: yu199195/Raincat
@Override
public List<TransactionRecover> listAllByDelay(final Date date) {
Query query = new Query();
query.addCriteria(new Criteria("status")
.in(TransactionStatusEnum.BEGIN.getCode(),
TransactionStatusEnum.FAILURE.getCode(),
TransactionStatusEnum.ROLLBACK.getCode()))
.addCriteria(Criteria.where("lastTime").lt(date));
final List<MongoAdapter> mongoBeans =
template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoBeans)) {
return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
}
return null;
}
代码示例来源:origin: yu199195/myth
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);
if (CollectionUtils.isNotEmpty(mongoAdapters)) {
final List<LogVO> recoverVOS =
代码示例来源:origin: yu199195/hmily
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);
if (CollectionUtils.isNotEmpty(mongoAdapters)) {
final List<HmilyCompensationVO> recoverVOS =
代码示例来源:origin: yu199195/Raincat
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);
if (CollectionUtils.isNotEmpty(mongoAdapters)) {
final List<TransactionRecoverVO> recoverVOS =
代码示例来源:origin: kaaproject/kaa
.include(EP_USE_RAW_SCHEMA);
List<EndpointProfileDto> endpointProfileDtoList = convertDtoList(
mongoTemplate.find(query, getDocumentClass()));
代码示例来源:origin: spring-projects/spring-integration
@Override
public Collection<Message<?>> getMessagesForGroup(Object groupId) {
Assert.notNull(groupId, "'groupId' must not be null");
Query query = groupOrderQuery(groupId);
List<MessageDocument> documents = this.mongoTemplate.find(query, MessageDocument.class, this.collectionName);
return documents.stream()
.map(MessageDocument::getMessage)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public Collection<Message<?>> getMessagesForGroup(Object groupId) {
Assert.notNull(groupId, "'groupId' must not be null");
Query query = whereGroupIdOrder(groupId);
List<MessageWrapper> messageWrappers = this.template.find(query, MessageWrapper.class, this.collectionName);
return messageWrappers.stream()
.map(MessageWrapper::getMessage)
.collect(Collectors.toList());
}
代码示例来源:origin: lianggzone/springboot-action
public List<Author> findAuthorList() {
Query query = new Query();
return this.mongoTemplate.find(query, Author.class);
}
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
@Override
public <T> List<T> find(Query query, Class<T> entityClass) {
return find(query, entityClass, operations.determineCollectionName(entityClass));
}
代码示例来源:origin: timebusker/spring-boot
@Override
public List<PersonEntity> findByParams(Map params) {
Query query = new Query();
Iterator<String> iterator = params.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
query.addCriteria(Criteria.where(key).lt(params.get(key)));
}
List<PersonEntity> list = mongoTemplate.find(query, PersonEntity.class);
return list;
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
@Nullable
@Override
public <T> T findOne(Query query, Class<T> entityClass, String collectionName) {
Assert.notNull(query, "Query must not be null!");
Assert.notNull(entityClass, "EntityClass must not be null!");
Assert.notNull(collectionName, "CollectionName must not be null!");
if (ObjectUtils.isEmpty(query.getSortObject()) && !query.getCollation().isPresent()) {
return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass);
} else {
query.limit(1);
List<T> results = find(query, entityClass, collectionName);
return results.isEmpty() ? null : results.get(0);
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithDefaultMongoFactory() throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapter", MessageChannel.class);
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
channel.send(message);
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
assertNotNull(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data"));
context.close();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithMongoConverter() throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithConverter", MessageChannel.class);
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
channel.send(message);
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
assertNotNull(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data"));
context.close();
}
内容来源于网络,如有侵权,请联系作者删除!