【问题标题】:Make @PageableDefault parameters configurable via properties通过属性使@PageableDefault 参数可配置
【发布时间】:2018-04-25 14:29:26
【问题描述】:

在 Spring MVC 控制器中,我想使用属性文件中的默认 Pageable 值。

@RequestMapping
public String list(Model model, @PageableDefault(size = 5, sort = "title") Pageable pageable) {
    // ...
}

我试着简单地写size = properties.getSize(),但它需要一个常量。

如何通过属性文件使sizesort参数可配置?

  • 春天 5
  • Spring Boot 2

【问题讨论】:

    标签: spring spring-mvc spring-boot


    【解决方案1】:
     # DATA REST (RepositoryRestProperties)
    spring.data.rest.base-path= # Base path to be used by Spring Data REST to expose repository resources.
    spring.data.rest.default-page-size= # Default size of pages.
    spring.data.rest.detection-strategy=default # Strategy to use to determine which repositories get exposed.
    spring.data.rest.enable-enum-translation= # Enable enum value translation via the Spring Data REST default resource bundle.
    spring.data.rest.limit-param-name= # Name of the URL query string parameter that indicates how many results to return at once.
    spring.data.rest.max-page-size= # Maximum size of pages.
    spring.data.rest.page-param-name= # Name of the URL query string parameter that indicates what page to return.
    spring.data.rest.return-body-on-create= # Return a response body after creating an entity.
    spring.data.rest.return-body-on-update= # Return a response body after updating an entity.
    spring.data.rest.sort-param-name= # Name of the URL query string parameter that indicates what direction to sort results.
    

    或查找属性here

    【讨论】:

    • 是的,但这控制了每个 Pageable 对象。我想控制这个特定的。所以我可以为不同的(网站)页面配置不同的页面大小。特别是没有办法进行默认排序。
    • 然后您可以创建自己的注释来处理 Spel。看看PageableDefault是怎么处理的here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多