首页 > 解决方案 > Create endpoint from query by method name, that is pageable/sortable

问题描述

I'm very new to spring boot, and I have a simple CRUD service that has a RestRepositoryResource:

@RepositoryRestResource
public interface CatalogueOrderRepository extends JpaRepository<CatalogueOrder, Long>,
    QuerydslPredicateExecutor<CatalogueOrder> {
}

I'm trying to create a custom endpoint, that can perform a pageable/sortable query for order statuses NOT equal to the provided query parameter. I attempted the following:

@GetMapping("/test")
Page<CatalogueOrder> findByOrderStatusNot(String orderStatus, Pageable page);

When I attempt to hit the endpoint /test, I get a 404 error.

Am I exposing the endpoint wrong? And if so, have I defined the method correctly for what I am trying to achieve?

标签: javaspring-bootjpaspring-data-jpaspring-rest

解决方案


也许您忘记@RestController在控制器中设置注释。

这样做并尝试再次调用http://localhost:8080/test

来源:https ://spring.io/guides/gs/rest-service/


推荐阅读