【Mybatis-Plus】【异常】Inferred type ‘E‘ for type parameter ‘E‘ is not within its bound;
问题描述
今天继承Mybatis-Plus里面的BaseMapper做的Dao层接口,实现selectPage()方法,但是一直报异常,代码和报错信息如下:
@Service
public class CategoryServiceImpl implements CategoryService {@Autowiredprivate CategoryDao categoryDao;@Overridepublic IPage<Category> findPage(PageAndQuery p) {IPage<Category> page= new Page<>(p.getPage(),p.getPageSize());//正常来说,这里应该返回一个IPage<Category>类型的对象,但是返回的却是一个类型E e//鼠标悬停,报错信息如下:Inferred type 'E' for type parameter 'E' is not within its bound; should implement 'com.baomidou.mybatisplus.core.metadata.IPage<com.itheima.dao.CategoryDao>'E e = categoryDao.selectPage(page, null);//这里忽略,因为上面已经有问题了,所以不往下返回值了return null;}
}
我很奇怪,是不是这个方法不能传null的参数呢?于是我去查看了源码:
/*** 根据 entity 条件,查询全部记录(并翻页)* @param page 分页查询条件(可以为 RowBounds.DEFAULT)* @param queryWrapper 实体对象封装操作类(可以为 null)*/<E extends IPage<T>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
源码说这个方法可以为空,那就不是参数的问题。
于是我运行了一下程序,想要得到更详细的提示,报错结果如下:
Error:(23, 26) java: 无法将接口 com.baomidou.mybatisplus.core.mapper.BaseMapper<T>中的方法 selectPage应用到给定类型;需要: E,com.baomidou.mybatisplus.core.conditions.Wrapper<com.itheima.dao.CategoryDao>找到: com.baomidou.mybatisplus.core.metadata.IPage<com.itheima.bean.Category>,<nulltype>原因: 推断类型不符合上限推断: com.baomidou.mybatisplus.core.metadata.IPage<com.itheima.bean.Category>上限: com.baomidou.mybatisplus.core.metadata.IPage<com.itheima.dao.CategoryDao>
报错第2-3行显示:需要CategoryDao,找到Category,所以类型不匹配
我就很奇怪,这里要的不是实体类Category吗?怎么会去找CategoryDao接口呢?于是我去接口文件看了一下,代码如下:
import com.baomidou.mybatisplus.core.mapper.BaseMapper;public interface CategoryDao extends BaseMapper<CategoryDao> {}
额,原来是犯了一个低级错误,把BaseMapper里面的类型写成CategoryDao接口了,这个类型应该写实体类Category的。
修改代码如下:
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.bean.Category;public interface CategoryDao extends BaseMapper<Category> {}
---------------------------------------------------------------------------------------@Service
public class CategoryServiceImpl implements CategoryService {@Autowiredprivate CategoryDao categoryDao;@Overridepublic IPage<Category> findPage(PageAndQuery p) {IPage<Category> page= new Page<>(p.getPage(),p.getPageSize());IPage<Category> iPage = categoryDao.selectPage(page, null);return null;}
}
编译成功!
最后再改一下返回值就好了就好了
总结:
- Mybatis可以使用一个简单的XML配置文件或者Annotation来配置和匹配实体。
- 在Mybatis-Plus中,也可以通过继承BaseMapper< T >,并在泛型T中指定实体的类型匹配接口和实体。
- 遇到错误要仔细看报错,如果报错不明显,可以运行一下看详细错误,找到反常的地方。
- 类型不符合的情况,可以检查一下泛型是否指定错误了。
【Mybatis-Plus】【异常】Inferred type ‘E‘ for type parameter ‘E‘ is not within its bound;相关推荐
- SpringBoot:Inferred type 'S' for type parameter 'S' is not within its bound
在使用springboot 方法报错: Inferred type 'S' for type parameter 'S' is not within its bound; should extends ...
- Spring data报错:Inferred type 'S' for type parameter 'S' is not within its bound;
Spring data报错:Inferred type 'S' for type parameter 'S' is not within its bound; 参照 org.springframewo ...
- Inferred type 'S' for type parameter 'S' is not within its bound
Inferred type 'S' for type parameter 'S' is not within its bound springboot报错内容: Inferred type 'S' f ...
- Inferred type S for type parameter S is not within its bound
springboot报错内容: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxx ...
- 使用SpringBoot报错:Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound。【解决办法】
❌一.错误展示 使用SpringBoot时出现如下错误: Inferred type 'S' for type parameter 'S' is not within its bound 错误代码: ...
- Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
文章目录 出现场景 解决方案 分开处理(推荐) 判断类型 出现场景 使用Dio时,网络请求可能会出现异常,需要用try catch捕获. 捕获代码如下 try {var response = awai ...
- 异常: No enclosing instance of type xx is accessible. Must qualify (Java 内部类)
异常 前言. 开发时候遇到内部类的问题. 异常 No enclosing instance of type SparkProgrammingGuide is accessible. Must qual ...
- 异常处理:el表达式数据类型转换异常 Cannot convert B36 of type class java.lang.String to class java.lang.Long
异常处理:el表达式数据类型转换异常 Cannot convert B36 of type class java.lang.String to class java.lang.Long 参考文章: ( ...
- 2、Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound; should extend ‘com.yummy.sell.da
2.Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'com.yummy.sell.da ...
最新文章
- eclipse中output folder和deployment assembly用法有什么不同?
- iOS 清除未使用图标
- matlab中fill函数的使用方法
- 未能加载文件或程序集“System.Data.SQLite, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139...
- 【C语言练习】【指针】定义一个函数move,实现将长度为n、名为a的序列中,各元素依次顺序循环,右移m个位置
- Android Button字母自动全部大写的问题
- 飞鸽传书(http://www.freeeim.com)软件下载
- ComponentOne FlexGrid for WinForms 中文版快速入门(4)--设置单元格格式
- 细说Python Lambda函数的用法,建议收藏!
- 魅族16T官网开启预约:骁龙855+4400mAh大电池
- HDU2009 求数列的和【迭代】
- C语言 二进制文件读写实例讲解
- css3实现椭圆轨迹运动
- L1、L2正则regularization和weight decay
- Jmeter循环获取JDBC查询结果及断言数据库查询结果
- TeamTalk源码分析之win-client
- 【Canvas】JavaScript用Canvas制作美丽的对称图案
- (转)Unity十大插件
- python3 selenium web自媒体百家号企鹅号大鱼号acfun站,自动化上传视频以及经验总结分享
- 椭圆曲线密码体制(ECC)
热门文章
- laravel 项目笔记之SendCloud 驱动
- 义隆单片机学习笔记之(三) 应用例程
- 12306html布局,12306-Assistant
- matlab编写扫雷,MATLAB版本的扫雷小游戏
- 信用评分卡建模:决策树模型
- rad xe 5 使用教程_使用Rad轻松实现React在线样式
- Time-Evolving Graph Convolutional Recurrent Network for Traffic Prediction论文笔记
- pythonista模板_Python——Code Like a Pythonista: Idiomatic Python
- python如何赚外快 淘宝_Python如何爬取淘宝MM呢?教你一招
- python-伪随机数生成器