pageablehandlermethodargumentresolvercustomizer使用默认的存储库方法,但不在自定义控制器spring引导中传递

q35jwt9p  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(371)

我添加了@configuration

@Configuration
public class RespositoryConfiguration {
    @Bean
    public PageableHandlerMethodArgumentResolverCustomizer customize() {
        return p -> {
            p.setOneIndexedParameters(true);
        };
    }
}

这会将页面中的数字设置为1,并将其设置为默认存储库。

"page": {
            "size": 5,
            "totalElements": 11,
            "totalPages": 3,
            "number": 1
        }

但当使用自定义控件获取时,它不会将数字设置为1。
这是我的控制器:

@GetMapping
        public ResponseEntity<ResponseMessage<?>> getAll(
                Pageable pageable,
                PagedResourcesAssembler assembler,
                PersistentEntityResourceAssembler resourceAssembler) throws Exception {
            System.out.println(pageable.getPageNumber());
            ResponseMessage responseMessage = itemService.findAll(pageable, assembler, resourceAssembler);
            return new ResponseEntity<ResponseMessage<?>>(responseMessage, HttpStatus.OK);
        }

这是我的服务:

public ResponseMessage findAll(Pageable pageable, PagedResourcesAssembler assembler,
                                   PersistentEntityResourceAssembler resourceAssembler) throws Exception {
        Page<Item> itemList = itemRepository.findAll(pageable);
        Page<ItemDto> itemDtoListResponse = itemList.map(itemMapper::toDto);

        ResponseMessage responseMessage = ResponseMessage.withResponseData(assembler.toModel(itemDtoListResponse),
                                                                           "Item List", "Info");
        return responseMessage;

    }

结果仍然是:

"page": {
            "size": 5,
            "totalElements": 11,
            "totalPages": 3,
            "number": 0
        }

我的控制器或服务缺少什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题