Spring Data Mongo @PageableDefault-如何使用@Value设置常量值?

时间:2019-05-13 10:42:54

标签: mongodb spring-boot spring-data-mongodb pageable

我已经遍历了链接:Set default page size for JPA Pageable Object,并试图通过属性文件来配置@PageableDefault的参数,但是由于@PageableDefault接受恒定值,因此我们无法使其可配置。有任何快速帮助吗?

此外,WebMvcConfigurerAdapter也已弃用。我正在使用Spring Boot V 2.1.x.RELEASE

private static final int DEFAULT_PAGE_NUMBER = 0;
private static final int DEFAULT_PAGE_SIZE = 50;

@RequestMapping(value = API_VERSION_1_OBSERVATION,
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<ApiAttachmentObservation>> findObservations(
    @RequestParam(required = false) String encounterId,
    @RequestParam(required = false) String patientId,
    @PageableDefault(page = DEFAULT_PAGE_NUMBER, size = DEFAULT_PAGE_SIZE)
    @SortDefault.SortDefaults({
        @SortDefault(sort = "dateRecorded", direction = Sort.Direction.DESC),
        @SortDefault(sort = "encounterId", direction = Sort.Direction.ASC)
    })
    Pageable pageable) throws URISyntaxException
    {
        LOGGER.info(String.format("REST request to find observations - [patientId : %s] & [encounterId : %s] & [pageable : %s]", patientId, encounterId, pageable));
        Page<ApiAttachmentObservation> page = observationService.findObservations(encounterId, patientId, pageable);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, API_VERSION_1_OBSERVATION);
        return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
    }

我想使用DEFAULT_PAGE_NUMBER通过属性文件来配置DEFAULT_PAGE_SIZE@Value

0 个答案:

没有答案