神魔皆在一念间 2021-06-25 16:12 采纳率: 50%
浏览 181
已结题

page与ArrayList 不能强制转换

源码
 

String currentPage = req.getParameter("currentPage");

        Integer num = 1;
        if("".equals(currentPage) || currentPage == null){
            num = 1;
        }else{
            num = Integer.parseInt(currentPage);
        }

        CSService service = new CSServiceImpl();

        //分页 PageHelper
        PageHelper.startPage(num,20);
        Page page = (Page) service.getCSMapper();

        PageInfo<CS> pageInfo = page.toPageInfo();

        req.setAttribute("page",pageInfo);
        req.getRequestDispatcher("page.jsp").forward(req,resp);

报错

java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page
    at com.aowin.controller.GetAllCSController.doGet (GetAllCSController.java:34)
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service (ServletHolder.java:1450)
    at org.eclipse.jetty.servlet.ServletHolder.handle (ServletHolder.java:799)
    at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter (ServletHandler.java:1626)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter (WebSocketUpgradeFilter.java:285)
    at org.eclipse.jetty.servlet.FilterHolder.doFilter (FilterHolder.java:193)
    at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter (ServletHandler.java:1601)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:548)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:602)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:235)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:1624)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1435)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:188)
    at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:501)
    at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:1594)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:186)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1350)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:191)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:146)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle (Server.java:516)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1 (HttpChannel.java:388)
    at org.eclipse.jetty.server.HttpChannel.dispatch (HttpChannel.java:633)
    at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:380)
    at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:277)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable (FillInterest.java:105)
    at org.eclipse.jetty.io.ChannelEndPoint$1.run (ChannelEndPoint.java:104)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:383)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:882)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run (QueuedThreadPool.java:1036)
    at java.lang.Thread.run (Thread.java:748)

提示不能转换 找不出问题

  • 写回答

2条回答 默认 最新

  • 神魔皆在一念间 2021-06-26 18:09
    关注
    public class GetAllCSController extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String currentPage = req.getParameter("currentPage");
    
            Integer num = 1;
            if("".equals(currentPage) || currentPage == null){
                num = 1;
            }else{
                num = Integer.parseInt(currentPage);
            }
    
            CSService service = new CSServiceImpl();
    
            //分页 PageHelper
            PageHelper.startPage(num,20);
            Page page = (Page) service.getAllCSByPage();
    
            PageInfo<CS> pageInfo = page.toPageInfo();
    
            req.setAttribute("page",pageInfo);
            req.getRequestDispatcher("page.jsp").forward(req,resp);
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req,resp);
        }
    }

    原来是这样的 我直接弃用 我自己写了一个分页bug直接解决

    public class GetAllCSController extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            Integer currentPage = Integer.valueOf(req.getParameter("currentPage"));
            CSService service = new CSServiceImpl();
            List<CS> ls=service.getCSMapper();
            PageInfo pageInfo = new PageInfo(ls, currentPage, 20);
            req.setAttribute("page",pageInfo);
            req.getRequestDispatcher("page.jsp").forward(req,resp);
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req,resp);
        }
    }

    我现在直接把转换给跳过

     

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 已采纳回答 4月14日

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?