欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSM框架分页查询NullPointerException

程序员文章站 2024-03-14 19:58:23
...

SSM框架分页查询NullPointerException

分页插件

  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
    <port>80</port>
    <path>/</path>
    <uriEncoding>utf-8</uriEncoding>
    </configuration>
 </plugin>

报错信息

 Servlet.service() for servlet [DispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException

解决方法

在getAll方法中输出list,控制台能得倒数据,但不能根据size来打印页面展示总条数,可能怀疑size的参数没有传进去
错误代码:

 @GetMapping("/{page}/{size}")
    public List<User> getAll(@PathVariable Integer page, Integer size) {
        System.out.println(service);
        List<User> list = service.getAll(page, size);
        System.out.println(list);
        return list;
    }

@PathVariable 这个注解只对page添加,并没有对size添加
正确代码

@GetMapping("/{page}/{size}")
    public List<User> getAll(@PathVariable Integer page, @PathVariable Integer size) {
        System.out.println(service);
        List<User> list = service.getAll(page, size);
        System.out.println(list);
        return list;
    }

SSM框架分页查询NullPointerException