是否可以在没有实际存储库的情况下使用 spring-data-rest-webmvc? [英] Is it possible to use spring-data-rest-webmvc without an actual Repository?

查看:26
本文介绍了是否可以在没有实际存储库的情况下使用 spring-data-rest-webmvc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能听起来很有趣,但我认为这应该是可能的.

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.

查看代码,我认为应该是可能的,因为使用CrudMethodsRepositoryInvoker 访问方法.我相信这需要 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.

  1. 启用自定义存储库 (@EnableCustomRepositories)
  2. 注释符合条件的实体 (@Custom)
  3. 创建存储库(扩展CustomRepository)
  4. 添加自定义行为:
  1. 让存储库扩展带有 Custom 后缀的新接口
  2. 使用 Impl 前缀创建新接口的实现
  3. 添加一个或多个名为 findOnesavefindAlldelete 的 CRUD 方法(参见 DefaultCrudMethods)
  4. 添加用 @Query 注释的查询方法
  1. Let repository extend a new interface with the Custom suffix
  2. Create an implementation of the new interface with the Impl prefix
  3. Add one or more CRUD methods named findOne, save, findAll, delete (see DefaultCrudMethods)
  4. Add query methods annotated with @Query

  • 使用 spring-data-rest
  • 导出存储库

  • Export repository using 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屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆