How to add custom method to Spring Data JPA

后端 未结 12 2018
盖世英雄少女心
盖世英雄少女心 2020-11-22 12:58

I am looking into Spring Data JPA. Consider the below example where I will get all the crud and finder functionality working by default and if I want to customize a finder t

12条回答
  •  独厮守ぢ
    2020-11-22 13:19

    There is another issue to be considered here. Some people expect that adding custom method to your repository will automatically expose them as REST services under '/search' link. This is unfortunately not the case. Spring doesn't support that currently.

    This is 'by design' feature, spring data rest explicitly checks if method is a custom method and doesn't expose it as a REST search link:

    private boolean isQueryMethodCandidate(Method method) {    
      return isQueryAnnotationPresentOn(method) || !isCustomMethod(method) && !isBaseClassMethod(method);
    }
    

    This is a qoute of Oliver Gierke:

    This is by design. Custom repository methods are no query methods as they can effectively implement any behavior. Thus, it's currently impossible for us to decide about the HTTP method to expose the method under. POST would be the safest option but that's not in line with the generic query methods (which receive GET).

    For more details see this issue: https://jira.spring.io/browse/DATAREST-206

提交回复
热议问题