问题描述
- Cannot cast from List<Object> to List<Professor>
-
一个简单的Spring mvc mybatis框架的CRUD实例。但是下面DAOIMPL里面代码报错,改不了首先interface IProfessorDao写了
public List findAll();然后IProfessorDaoImpl里面下面方法报错
public List findAll()
{
// TODO Auto-generated method stub
String sql = this.getStatementId(Professor.class, SELECTALL);
List list = (List)sqlSession.selectList(sql);
return list;}
其中(List)sqlSession.selectList(sql); 这里提示 Cannot cast from List to List
SQLMAPPER设置也没有问题,代码如下select * from ALL_EXP_LIST_TBL ;
求助怎么解决
解决方案
可以改成List list = (List)sqlSession.selectList(sql);试试,List是转换不成List的
解决方案二:
- Set & Map?? A?? ?--? object/key exists in set/map???B????--? object/key to be added to set/map?? If and only if???????? (B?==?A || B.equals(A)) &&?B.hashCode == A.hashCode???then??keyAdd will overwr......
答案就在这里:What's the effect of hashCode() & equals() when adding object to List/Set/Map
解决方案三:
可以改成List《Professor》 list = (List《Professor》)sqlSession.selectList(sql);试试,List《Professor》是转换不成List《Object》的
时间: 2024-09-19 11:48:03