Enable HAL serialization in Spring Boot for custom controller method

后端 未结 3 652
清歌不尽
清歌不尽 2020-11-29 06:47

I\'m trying to build a RESTful API with Spring Boot using spring-boot-starter-data-rest. There are some entities: accounts, transactions, categories and users - just the usu

3条回答
  •  隐瞒了意图╮
    2020-11-29 07:46

    You do not need to create your own controller to limit query results or sort the results. Just create a query method in your repository:

    public interface TransactionRepository extends MongoRepository {
    
        List findFirst10ByOrderByDateDesc();
    
    }
    

    Spring Data REST will automatically export it as a method resource at /transactions/search/findFirst10ByOrderByDateDesc.

提交回复
热议问题