1

I am writing a Java Spring REST server using Spring Boot. This is the dependency list:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
</dependencies>

This is a part of my a controller class:

@RequestMapping(path = "/", method = RequestMethod.GET)
public GenericResponse<List<Trip>> getUserTrips(Pageable pageable , @RequestParam("owner") String owner) {
    List<Trip> trips = tripRepository.findByOwner(owner , pageable);
    for (Trip trip : trips) {
        Link link = linkTo(methodOn(TripController.class).getTripInfo(trip.getTripId())).withSelfRel();
        trip.add(link);
    }
    return new GenericResponse<List<Trip>>(200, "Success", trips);
}

When compiled, I got the following error:

method getUserTrips in class com... cannot be applied to given types required org.sptringframework.data.domain.Pageable, java.lang.String found: java.lang.String reason: actual and formal argument lists differ in length

I don't understand. I thought Pageable automatically parse the ?page=x&pageSize=y to the pageable var.

Do I forget to add any dependencies? What is wrong?

I do not use WebMv (it's not in my dependency list) Is it why this does not work?

Tran Triet
  • 1,257
  • 2
  • 16
  • 34
  • Possible duplicate of [Spring4 MVC Controller Pageable not working](http://stackoverflow.com/questions/34459658/spring4-mvc-controller-pageable-not-working) – Vasu Apr 13 '17 at 18:25
  • can i have your tripRepository – VISHWANATH N P Apr 14 '17 at 05:09
  • @VISHWANATHNP here: package com.tripmaester.repository; import java.util.List; import java.util.UUID; import org.springframework.data.mongodb.repository.MongoRepository; import com.tripmaester.models.Trip; import org.springframework.data.domain.*; public interface TripRepository extends MongoRepository { public List findByOwner(String owner, Pageable pageable); } – Tran Triet Apr 14 '17 at 05:24
  • 1
    please check this http://ankushs92.github.io/tutorial/2016/05/03/pagination-with-spring-boot.html link – VISHWANATH N P Apr 14 '17 at 05:30
  • 1
    please check this link http://ankushs92.github.io/tutorial/2016/05/03/pagination-with-spring-boot.html – VISHWANATH N P Apr 14 '17 at 05:31
  • sorry, I tried to make the previous comment look better but still haven't figured out how. I used to link you gave me! I update my controller and repository according to this link. However, there are some differences because my project use MongoDB and MongoRepository already extends PagingAndSortingRepository. – Tran Triet Apr 14 '17 at 05:41

0 Answers0