簡體   English   中英

如何使用 jpa 模板編寫查詢

[英]How to write query using jpa template

我在這里使用了 mongo 存儲庫和 mongo 模板來編寫 mongodb 查詢。

public interface Repository extends MongoRepository<Entity, String> {}

private final MongoTemplate template;
public Scheduling(MongoTemplate template) {
    this.template = template;
}
Query query = new Query();       
query.addCriteria(Criteria.where("status").is("READY")).with(Sort.by(Sort.Order.asc("timestamp")));
List<Entity> entityList = template.find(query, Entity.class);

如何使用 jpa 模板而不是 mongo 模板來查詢 mongodb? 我需要編寫與上述相同的查詢,但使用 jpa 模板提前致謝。

您可以使用這種 JPA 查詢並參考提到的鏈接:

List<ExecutorEntity> findExecutorEntityByStatusAndSort(String status, Sort sort);

https://www.devglan.com/spring-boot/spring-data-mongodb-queries

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM