0

I've the following class:

@RepositoryRestResource(collectionResourceRel = "books", path = "books")
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {
    List<Book> findByTitle(Pageable pageable, @Param("title") String title);
}

When I call /books I get nice pagination information, but with findByTitle method I don't get any pagination information (although pagination works, no next,prev links nor any "count" fields)

What should I add to get the same HATEOAS experience with the /books response?

When I call http://127.0.0.1:8888/books/search/findByTitle?title=bc&page=0

I get this response:

    {
  "_embedded" : {
    "books" : [ {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/4"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/4"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/5"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/5"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/6"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/6"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/7"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/7"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/8"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/8"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/9"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/9"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/10"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/10"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/11"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/11"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/12"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/12"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/13"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/13"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/14"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/14"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/15"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/15"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/16"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/16"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/17"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/17"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/18"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/18"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/19"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/19"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/20"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/20"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/21"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/21"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/22"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/22"
        }
      }
    }, {
      "title" : "bc",
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8888/books/23"
        },
        "book" : {
          "href" : "http://127.0.0.1:8888/books/23"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://127.0.0.1:8888/books/search/findByTitle?title=bc&page=0"
    }
  }
}
Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70
EralpB
  • 1,621
  • 4
  • 23
  • 36

1 Answers1

1

I think your repository should return a org.springframework.data.domain.Page instead of a List.

@RepositoryRestResource(collectionResourceRel = "books", path = "books")
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {
    Page<Book> findByTitle(Pageable pageable, @Param("title") String title);
}
Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70
  • Now that's one step closer, with Page it returned the page statistics (count etc.) but HATEOAS links (next,prev,last) are still missing. :) – EralpB Jan 23 '17 at 13:17
  • 1
    Oh it worked, I must've missed something in my first try, thank you! – EralpB Jan 23 '17 at 13:30