java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.miemiedev.mybatis.paginator.domain.PageList
在网上找了例子都是强转可以的。为什么本人这儿强转就报错。
spring配置文件
在网上找了例子都是强转可以的。为什么本人这儿强转就报错。
spring配置文件
<!-- 配置sessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据源 --> <property name="dataSource" ref="ds" /> <!-- 映射mapper文件 --> <property name="mapperLocations" value="classpath:sqlmap/*.xml"/> <property name="configLocation" value="classpath:sqlMapConfig.xml"></property> </bean>
mapper文件
<select id="queryEmpList" parameterType="org.liukai.testMybatisPaginator.entity.po.Emp" resultMap="empPO" ><!-- resultMap对应上面的 <resultMap>标签的id--> select * from liukai_emp WHERE 1 = 1 <if test="empId != null "> and empId = #{empId}</if> <if test="name != null and name != "" "> and name = #{name}</if> <if test="age != null "> and age = #{age}</if> <if test="sal != null "> and sal = #{sal}</if> <if test="marry != null "> and marry = #{marry}</if> </select>
mybatis配置文件
<configuration> <settings> <setting name="cacheEnabled" value="false" /> <setting name="lazyLoadingEnabled" value="true" /> <setting name="multipleResultSetsEnabled" value="true" /> <setting name="useColumnLabel" value="true" /> <setting name="defaultExecutorType" value="REUSE" /> <setting name="defaultStatementTimeout" value="25000" /> </settings> <plugins> <plugin interceptor="com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor"> <property name="dialectClass" value="com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect"/> </plugin> </plugins> <mappers> </mappers> </configuration>
dao部分
public List<Emp> queryEmpList(PageBounds pageBounds, Emp emp) { List<Emp> resultList = getSqlSession().selectList("emp.queryEmpList", emp, pageBounds); //PageList<Emp> list = (PageList<Emp>) this.getSqlSession().selectList("emp.queryEmpList", emp, pageBounds); //PageList list = new PageList(pageList); //PaginationSupport<Emp> resultList = new PaginationSupport<Emp>(list.getPaginator(), list); return resultList; }
service部分 就是这儿强转报错
public PaginationSupport<Emp> queryEmpList(Emp emp, Page page) { PageBounds pageBounds = new PageBounds(); //System.out.println(page); //System.out.println("--" + page.getCurrentPage()); pageBounds.setPage(1); pageBounds.setLimit(5); //PaginationSupport<Emp> list = empDao.queryEmpList(pageBounds, emp); List<Emp> list = empDao.queryEmpList(pageBounds, emp); PageList<Emp> pageList = (PageList<Emp>)list; PaginationSupport<Emp> resultList = new PaginationSupport<Emp>(pageList.getPaginator(), pageList); return resultList; }
解决方案
10
代码看得有点糊涂,LZ想实现的是,数据分页(数据库级别)?好使内存分页(从数据库取出数据集,然后在分页)?
10
两个完全不一样的对象可以这样强转?