문제

I am trying to create a custom query from the Spring guide : Accessing MongoDB Data with REST according to the Reference 4.4 Custom Implementations. But my custom method is not available from the repository's REST interface (/user/search).

(e.g. Browser is unable to find localhost:8080/user/search/GetByKidsAge?age=1)

Could someone help me to figured this out and give me some suggestions? Thanks a lot !!

Below is my code:

UserRepositoryCustom.java

public interface UserRepositoryCustom {     

    public List<User> GetByKidsAge(@Param("age") int age);
}

UserRepositoryImpl.java

public class UserRepositoryImpl implements UserRepositoryCustom {

    @Override
    public List<User> GetByKidsAge(int age) {

        return /*perform query*/;

    }
}

UserRepository.java

@RepositoryRestResource(collectionResourceRel = "user", path = "user")
public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom {

        List<User> findByLastName(@Param("name") String name);  
}
도움이 되었습니까?

해결책

This is by design. As soon as you start implementing a repository method manually we cannot know whether GET or POST is the right HTTP method as whether the execution is idempotent depends on how you implement it.

So the way to go would be implementing a custom controller and expose those methods using the adequate HTTP method. That said, there's a ticket in our tracker to provide means to define the way these methods should be exposed as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top