Reputation: 132
Hi I am trying to override the default param name fo page size in Spring JPA to match that of the Kendo UI grid which needs to use
http://localhost:8080/retailers/all?page=1&pageSize=5
The JPA is producing
http://localhost:8080/retailers/all?page=1&size=5
I have tried adding
spring.data.rest.page-param-name=page
spring.data.rest.limitParamName=pageSize
to the application properties, but it doesn't seem to make any difference to the project.
My controller looks like this
@RequestMapping(method = RequestMethod.GET, value = "retailers/all")
public ResponseEntity<Page<RetailerEntity>> retailers(Pageable pageable){
Page<RetailerEntity> retailers = retailerService.getAllRetailers(pageable);
return new ResponseEntity<>(retailers, HttpStatus.OK);
}
and the repository is using the out of the box implementation
public interface RetailerRepository extends PagingAndSortingRepository<RetailerEntity, Integer> {
}
Any help is appreciated.
Upvotes: 1
Views: 2563
Reputation: 156
This problem could be related to the spring boot version. Changing application.properties works only for Spring Boot 1.2+. If you are using 1.1 or earlier version, you have two options:
1) Create a RepositoryRestConfigurer
bean using a custom implementation of RepositoryRestConfigurerAdapter
.
@Configuration
class CustomRestMvcConfiguration {
@Bean
public RepositoryRestConfigurer repositoryRestConfigurer() {
return new RepositoryRestConfigurerAdapter() {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
}
};
}
}
2) Create a component with a custom implementation of RepositoryRestConfigurer
.
@Component
public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurerAdapter {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
}
}
These examples are for the basePath
property, you can change all the others in the same way.
You can check for more details: the documentation
Upvotes: 1