java - 找不到接口 org.springframework.data.domain.Pageable 的主要或默认构造函数
问题描述
我试图在我的 RestController 中实现 Pageable 并遇到此错误消息“No primary or default constructor found for interface org.springframework.data.domain.Pageable”的问题
我的控制器是
@GetMapping("/rest/category/all/page")
public Page<ItemCategory> getAllItemCategoryByPage(Pageable pageable){
Page<ItemCategory> categories = itemCategoryService.getAllItemCategoriesByPageable(pageable);
return categories;
}
我在这里做错了什么。它是一个 Spring Boot 2.0 应用程序。提前致谢!
解决方案
选择的解决方案是一种解决方法。您可以使用此配置使 Spring 自动解析参数:
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
@EnableSpringDataWebSupport
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
}
}
推荐阅读
- python - Nsetools API 在 ec2 实例上部署时不起作用
- shapefile - QGIS:QGIS3.10 中的矢量图层问题
- ios - 将从另一个协议继承的协议设置为关联类型会产生错误
- javascript - 为什么 state 的值在异步函数中只评估一次?
- google-sheets - 不同交易对中的买卖交易汇总为一个“成本”
- android - Android Jet Pack Jetifier:原因:无效的文字/长度设置
- python - 使用python过滤列表中的任何数字或列表中的任何字符串,而不使用另一个列表
- javascript - 如果子元素具有活动类,则 DOM 访问上一个元素的父元素
- python - 在 CMD 中获取 404 1668 并且无法连接我的 css 文件 im html
- r - 将 xml_node 列表转换为 xml_document