Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc ThymalLeaf |参数化段在一个th中:每个_Spring Mvc_Thymeleaf - Fatal编程技术网

Spring mvc ThymalLeaf |参数化段在一个th中:每个

Spring mvc ThymalLeaf |参数化段在一个th中:每个,spring-mvc,thymeleaf,Spring Mvc,Thymeleaf,我试图在th:each中使用参数化段,但遇到以下异常: EL1007E:在null上找不到属性或字段“author” 如果我得到了正确的答案,这意味着我试图访问其变量的对象为空,尽管通过SpringMVC应用程序中的断点和调试,我确信列表中有两个元素 这是控制器: @GetMapping("/") public String getHomePage(Model model) { log.info("Recupero la home-page");

我试图在th:each中使用参数化段,但遇到以下异常: EL1007E:在null上找不到属性或字段“author”

如果我得到了正确的答案,这意味着我试图访问其变量的对象为空,尽管通过SpringMVC应用程序中的断点和调试,我确信列表中有两个元素


这是控制器:

@GetMapping("/")
public String getHomePage(Model model) {
    log.info("Recupero la home-page");
    model.addAttribute("reviews", mainService.getAllReviews());
    return "home";
}
以下是th:each:

<div
    th:each="review: ${reviews}"
    th:assert="({review} != null)"
    th:replace="fragments/utilities :: test(author=${review.author},message=${review.review})"
></div>

以下是片段:

<div th:fragment="test(author, message)">
    <p th:text="${message}" class="mt-2 text-dark"></p>
    <h6 th:text="${author}"></h6>
</div>


以下是将网页返回给客户端之前运行时模型的屏幕截图:


怎么了?为什么它说查看对象为空?

您的主Thymeleaf模板有问题。您需要考虑哪个指示将首先运行
th:replace
,然后是
th:each
,并替换整个
元素。工作代码可能类似于

<th:block th:each="review: ${reviews}">
    <div th:replace="fragments/utilities :: test(author=${review.author},message=${review.review})"></div>
</th:block>

您的主Thymeleaf模板存在问题。您需要考虑哪个指示将首先运行
th:replace
,然后是
th:each
,并替换整个
元素。工作代码可能类似于

<th:block th:each="review: ${reviews}">
    <div th:replace="fragments/utilities :: test(author=${review.author},message=${review.review})"></div>
</th:block>