是否可以在没有实际存储库的情况下使用 spring-data-rest-webmvc? [英] Is it possible to use spring-data-rest-webmvc without an actual Repository?
问题描述
这个问题可能听起来很有趣,但我认为这应该是可能的.
The question may sound funny but I think this should be possible.
我想要的是使用一个完全自定义但像存储库一样公开的存储库.该服务具有获取、保存、删除和列出数据可能来自任意来源的对象的方法.
What I want is to use a repository that is purely custom but is exposed just like a Repository. This service would have methods to get, save, delete and list objects where the data could be from any arbitrary source.
查看代码,我认为应该是可能的,因为使用CrudMethods
和RepositoryInvoker
访问方法.我相信这需要 RepositoryFactoryInformation
的实现,该实现将由 Repositories
发现.我开始尝试了一下,它看起来像一个成熟的 spring-data-noop 模块.
Looking through the code, I think it should be possible since methods are accessed using CrudMethods
and RepositoryInvoker
. I belief this requires an implementation of RepositoryFactoryInformation
that will be discovered by Repositories
. I started experimenting a bit and it looks like a full-blown spring-data-noop module.
我是在正确的轨道上还是有更简单的方法来实现这一目标?
Am I on the right track or is there an easier way to accomplish this?
推荐答案
我已经写完了 spring-data-custom 创建完全自定义的 spring-data 存储库,允许自定义代码与 spring-data-rest 等一起使用.
I've ended up writing spring-data-custom to create fully customized spring-data repositories, allowing custom code to be used with spring-data-rest etc.
- 启用自定义存储库 (
@EnableCustomRepositories
) - 注释符合条件的实体 (
@Custom
) - 创建存储库(扩展
CustomRepository
) - 添加自定义行为:
- 让存储库扩展带有
Custom
后缀的新接口 - 使用
Impl
前缀创建新接口的实现 - 添加一个或多个名为
findOne
、save
、findAll
、delete
的 CRUD 方法(参见DefaultCrudMethods
) - 添加用
@Query
注释的查询方法
- Let repository extend a new interface with the
Custom
suffix - Create an implementation of the new interface with the
Impl
prefix - Add one or more CRUD methods named
findOne
,save
,findAll
,delete
(seeDefaultCrudMethods
) - Add query methods annotated with
@Query
spring-data-rest
spring-data-rest
(复制自 README)
正如@wwadge 正确提到的,spring-data-keyvalue 是另一种选择.存储库必须实现 KeyValueAdapter,例如MapKeyValueAdapter.
As @wwadge correctly mentioned, spring-data-keyvalue is an alternative. Repositories have to implement KeyValueAdapter, e.g. MapKeyValueAdapter.
这篇关于是否可以在没有实际存储库的情况下使用 spring-data-rest-webmvc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!