我已经遍历了链接: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
值