我想在没有数据库连接的情况下将数据存储在HashMap<>或ArrayList<>中。此外,我还想创建一个管理数据的类,比如按条件更新或获取数据。
在这种情况下,创建和使用存储库而不使用JpaRepository是否合适?或者有其他合适的方式吗?
@Repository
public interface ProductRepository {
private List<Product> productList; // = new ArrayList<>();
public Product getProductByid(int id) { ... };
public boolean updateProduct() { ... };
}
发布于 2020-10-11 18:31:58
您应该看看Spring Data Key Value文档:https://docs.spring.io/spring-data/keyvalue/docs/current/reference/html/#reference
Spring Data Key Value适用于使用键值存储的Spring应用程序。
下面是一个简单的例子:http://www.henryxi.com/spring-data-keyvalue-example
EDIT: As doctore在注释中正确陈述,此示例更适合您的情况:https://www.baeldung.com/spring-data-key-value
https://stackoverflow.com/questions/64302807
复制相似问题