环境 springboot2.1.3 maven3.3.9 thymeleafcontroller@GetMapping("/customerList")
    public String getCustomerList(
            @RequestParam(required = true) String pageNum,
            @RequestParam(required = true) String pageSize,
            Model model
    ) {        Integer pageNum1 = Integer.parseInt(pageNum);
        Integer pageSize1 = Integer.parseInt(pageSize);
        if (pageNum1 <= 0)
            pageNum1 = 1;
        if (pageSize1 <= 0 || pageSize1 >= 20)
            pageSize1 = 8;        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        User user = (User) request.getSession().getAttribute("user");
        List<Customer> customerList = null;
        try {
            Page<Customer> page = PageHelper.startPage(pageNum1, pageSize1);
            customerList = customerService.getCustomerList(user);
            PageInfo<Customer> pageInfo = new PageInfo<>(customerList, pageSize1);
            model.addAttribute("customerList", customerList);
            model.addAttribute("pageInfo", pageInfo);
            model.addAttribute("code", SUCCESS_CODE);
            model.addAttribute("message", SUCCESS_MSG);
            return "/page/customerList";
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ERROR_CODE, "获取客户列表失败").toGson();
        }
    }
html    <div style="position: relative">
        <nav aria-label="..." class="pag">
            <ul th:id="pagination" class="pagination" th:object="${pageInfo}" th:text="${pageInfo.prePage}">
                <li th:if="*{PrePage}">111</li>
        。。
${pageInfo}有数据PageInfo{pageNum=1, pageSize=8, size=8, startRow=1, endRow=8, total=112, pages=14, list=Page{count=true, pageNum=1, pageSize=8, startRow=0, endRow=8, total=112, pages=14, reasonable=true, pageSizeZero=false}[com.zhzj.saasoa.pojo.Customer@ad5bf84, com.zhzj.saasoa.pojo.Customer@44bcdcab, com.zhzj.saasoa.pojo.Customer@438b1da3, com.zhzj.saasoa.pojo.Customer@1b6c9d73, com.zhzj.saasoa.pojo.Customer@3ce23805, com.zhzj.saasoa.pojo.Customer@1e19e2b6, com.zhzj.saasoa.pojo.Customer@56492d3, com.zhzj.saasoa.pojo.Customer@7a1c0009], prePage=0, nextPage=2, isFirstPage=true, isLastPage=false, hasPreviousPage=false, hasNextPage=true, navigatePages=8, navigateFirstPage=1, navigateLastPage=8, navigatepageNums=[1, 2, 3, 4, 5, 6, 7, 8]}
${pageInfo.prePage}报错
16:21:25.154 logback [http-nio-8070-exec-1] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8070-exec-1] Exception processing template "/page/customerList": Exception evaluating SpringEL expression: "pageInfo.prePage" (template: "/page/customerList" - line 170, col 79)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "pageInfo.prePage" (template: "/page/customerList" - line 170, col 79)Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'prePage' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51)
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:406)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:109)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:328)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
... 65 common frames omitted
16:21:25.159 logback [http-nio-8070-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/management] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "pageInfo.prePage" (template: "/page/customerList" - line 170, col 79)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'prePage' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
不知道问题出在哪儿,开始怀疑是thymeleaf表达式用错。但排出了。我后来以为是返回的字符串,也不是。

解决方案 »

  1.   

    Property or field 'prePage' cannot be found on null
      

  2.   

    有值,
    PageInfo{pageNum=1, pageSize=8, size=8, startRow=1, endRow=8, total=112, pages=14, list=Page{count=true, pageNum=1, pageSize=8, startRow=0, endRow=8, total=112, pages=14, reasonable=true, pageSizeZero=false}[com.zhzj.saasoa.pojo.Customer@ad5bf84, com.zhzj.saasoa.pojo.Customer@44bcdcab, com.zhzj.saasoa.pojo.Customer@438b1da3, com.zhzj.saasoa.pojo.Customer@1b6c9d73, com.zhzj.saasoa.pojo.Customer@3ce23805, com.zhzj.saasoa.pojo.Customer@1e19e2b6, com.zhzj.saasoa.pojo.Customer@56492d3, com.zhzj.saasoa.pojo.Customer@7a1c0009], prePage=0, nextPage=2, isFirstPage=true, isLastPage=false, hasPreviousPage=false, hasNextPage=true, navigatePages=8, navigateFirstPage=1, navigateLastPage=8, navigatepageNums=[1, 2, 3, 4, 5, 6, 7, 8]}
      

  3.   

    ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8070-exec-1] Exception processing template "/page/customerList": Exception evaluating SpringEL expression: "pageInfo.prePage" (template: "/page/customerList" - line 170, col 79)看一下 170 行,debug 一下