Results 1 to 5 of 5

Thread: Spring-data-rest: displaying totalCount in search

  1. #1
    Join Date
    Jul 2012
    Location
    St. Louis, Missouri
    Posts
    15

    Default Spring-data-rest: displaying totalCount in search

    I'm using Spring-data-rest. I want to display the count of the data/values

    code:
    public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {

    Public Long findByName(@Param("name") Long name);

    }

    If I search by Name, I get all the data associated with it.
    But if I want only the count value instead of displaying the data, is there any way doing that?

    Please help with your ideas..
    Thanks.

  2. #2
    Join Date
    Jul 2006
    Location
    Lamar, Missouri USA
    Posts
    36

    Default

    I think you just need to define your @Query like you would in normal JPQL queries:

    Code:
    @Query("select count(p) from Person p where p.name = :name")
    public Long findByName(@Param("name") Long name);
    Jon Brisbin
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Jul 2012
    Location
    St. Louis, Missouri
    Posts
    15

    Default

    It is not working, giving blank page.
    Any other ideas..
    Last edited by Applebee; Aug 22nd, 2012 at 05:45 PM.

  4. #4
    Join Date
    Jul 2006
    Location
    Lamar, Missouri USA
    Posts
    36

    Default

    Looks like the query works but in the code I'm assuming you'll be returning an entity or a list of entities from searches. It's giving a 404 trying to find a repository for a Long.

    I'll get a fix for that up tomorrow morning.
    Jon Brisbin
    SpringSource
    http://www.springsource.com

  5. #5
    Join Date
    Jul 2012
    Location
    St. Louis, Missouri
    Posts
    15

    Default

    Yes, it is returning 404. From search I'm returning list of entities. So I want the totalCount of those entities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •