2017-06-14 108 views
1

你好我想在春天JPA覆蓋默認PARAM名FO頁面大小,以匹配其需要使用春季啓動自定義分頁參數

http://localhost:8080/retailers/all?page=1&pageSize=5

的JPA是生產

劍道UI電網

http://localhost:8080/retailers/all?page=1&size=5

我曾嘗試加入

spring.data.rest.page-param-name=page 
spring.data.rest.limitParamName=pageSize 

到應用程序屬性,但它似乎沒有任何區別的項目。

我的控制器看起來像這樣

@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); 
} 

和倉庫使用開箱實施

public interface RetailerRepository extends PagingAndSortingRepository<RetailerEntity, Integer> { 

} 

任何幫助表示讚賞。

+0

嗨,你能告訴我們你使用哪個春季啓動版本? – Mike

回答

0

此問題可能與彈簧啓動版本有關。 更改application.properties僅適用於Spring Boot 1.2+。 如果您使用1.1或更早版本,您有兩種選擇:

1)使用自定義實現RepositoryRestConfigurerAdapter創建一個RepositoryRestConfigurer bean。

@Configuration 
class CustomRestMvcConfiguration { 

    @Bean 
    public RepositoryRestConfigurer repositoryRestConfigurer() { 

    return new RepositoryRestConfigurerAdapter() { 

     @Override 
     public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
     config.setBasePath("/api"); 
     } 
    }; 
    } 
} 

2)創建一個自定義實現爲RepositoryRestConfigurer的組件。

@Component 
public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurerAdapter { 

    @Override 
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
    config.setBasePath("/api"); 
    } 
} 

這些示例適用於basePath屬性,您可以用相同的方式更改所有其他屬性。 你可以檢查更多的細節:the documentation

+0

我正在使用父啓動器1.5.4.RELEASE,它仍然不更新屬性文件中的條目。我已經能夠通過改變客戶端參數來解決它,但我認爲這會更容易。 – Nimo1981