ssm使用pagehelper进行分页时报错
西瓜菠萝 2018-02-23 03:00:44 不使用pagehelper进行分页时可以查询出数据,使用pagehelper进行分页时报错.
预估错误原因是sql中使用了union all,
pagehelper进行select count(0)报错.
1.使用PageHelper进行分页询
@RequestMapping("searchmyArticle.do")
@ResponseBody
public String searchmyArticle(HttpServletRequest request, HttpServletResponse response) throws IOException{
//获取默认行
String pageNum = request.getParameter("pageNum");
int curNum = (pageNum==null || "".equals(pageNum)) ? 1 : Integer.valueOf(pageNum);
//设置当前页及行数
PageHelper.startPage(curNum, 10);
/****** 分页 end*******/
log.info("[log]按条件筛选文章");
String userId = request.getParameter("userId");
String title = request.getParameter("sstj");
if(title != null) title = URLDecoder.decode(title, "UTF-8");
List<MhArticle> alist = articleService.findArticleByTitle(userId, title);
//把List集合以JSONArray的形式传到页面上处理
PageInfo<MhArticle> pi = new PageInfo<MhArticle>(alist);
//JSONArray array = JSONArray.fromObject(pi);
//response.getWriter().print(array);
return new Gson().toJson(pi);
}
2多表查询 使用了union all合并,sql在pl/sql运行没问题.
3报错信息如下:
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.SetOperationList.getSelects()Ljava/util/List;
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at com.qx.portal.util.LoginFilter.doFilter(LoginFilter.java:62)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.SetOperationList.getSelects()Ljava/util/List;
at com.github.pagehelper.parser.CountSqlParser.processSelectBody(CountSqlParser.java:180)
at com.github.pagehelper.parser.CountSqlParser.processFromItem(CountSqlParser.java:251)
at com.github.pagehelper.parser.CountSqlParser.processPlainSelect(CountSqlParser.java:207)
at com.github.pagehelper.parser.CountSqlParser.processSelectBody(CountSqlParser.java:172)
at com.github.pagehelper.parser.CountSqlParser.processFromItem(CountSqlParser.java:251)
at com.github.pagehelper.parser.CountSqlParser.processPlainSelect(CountSqlParser.java:207)
at com.github.pagehelper.parser.CountSqlParser.processSelectBody(CountSqlParser.java:172)
at com.github.pagehelper.parser.CountSqlParser.getSmartCountSql(CountSqlParser.java:86)
at com.github.pagehelper.dialect.AbstractDialect.getCountSql(AbstractDialect.java:55)
at com.github.pagehelper.util.SqlUtil.doIntercept(SqlUtil.java:139)
at com.github.pagehelper.util.SqlUtil.intercept(SqlUtil.java:84)
at com.github.pagehelper.PageHelper.intercept(PageHelper.java:50)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57)
at $Proxy182.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at sun.reflect.GeneratedMethodAccessor105.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
at $Proxy60.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at $Proxy107.findArticleByTitle(Unknown Source)
at com.qx.portal.service.MhArticleService.findArticleByTitle(MhArticleService.java:114)
at com.qx.portal.controller.MhArticleController.searchmyArticle(MhArticleController.java:260)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
... 24 more
<2018-2-23 上午10时07分43秒 CST> <Error> <HTTP> <BEA-101017> <[ServletContext@1908659476[app:_appsdir_QX_dir module:QX path:/QX spec-version:2.5], request: weblogic.servlet.internal.ServletRequestImpl@1b439463[
POST /QX/searchmyArticle.do HTTP/1.1
Connection: keep-alive
Content-Length: 29
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:7001
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3294.6 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:7001/QX/findArticle.do
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: password=; user=zhangru; JSESSIONID=QKXKhPzYLSkZyJBZv6mx78CN8P2sML5v6nWBNQJlDJzY57KpQt1s!888419628
]] Root cause of ServletException.
java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.SetOperationList.getSelects()Ljava/util/List;
at com.github.pagehelper.parser.CountSqlParser.processSelectBody(CountSqlParser.java:180)
at com.github.pagehelper.parser.CountSqlParser.processFromItem(CountSqlParser.java:251)
at com.github.pagehelper.parser.CountSqlParser.processPlainSelect(CountSqlParser.java:207)
at com.github.pagehelper.parser.CountSqlParser.processSelectBody(CountSqlParser.java:172)
at com.github.pagehelper.parser.CountSqlParser.processFromItem(CountSqlParser.java:251)
Truncated. see log file for complete stacktrace
>