Is it possible to use spring-data-rest-webmvc without an actual Repository?

前端 未结 2 1523
臣服心动
臣服心动 2021-01-15 19:06

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. Thi

2条回答
  •  清酒与你
    2021-01-15 19:52

    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. Enable custom repositories (@EnableCustomRepositories)
    2. Annotate eligible entities (@Custom)
    3. Create a repository (extend CustomRepository)
    4. Add custom behavior:
      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
    5. Export repository using spring-data-rest

    (copied from README)

    As @wwadge correctly mentioned, spring-data-keyvalue is an alternative. Repositories have to implement KeyValueAdapter, e.g. MapKeyValueAdapter.

提交回复
热议问题