An error happened during template parsing

created at 12-13-2021 views: 384

error

When learning springmvc, when using the controller layer to interact with thymeleaf, the model is defined in the controller layer, and the following error occurs when it is passed to thymeleaf:

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/main.html]")

There is no problem after repeated viewing, but later found that the object passed to the view can directly access the private members, and the get method cannot be used to obtain the member variables:

private String author = null;

public String getAuthor()
{
    return author;
}

soultion

Incorrect reference:

<p class="card-author" th:text="${list.getAuthor()}">This is the author</p>
<!-- So the view can't resolve the get method -->

The correct way:

<p class="card-author" th:text="${list.author}">This is the author</p>

This is easy to be misled. Generally speaking, private members cannot be accessed directly from the outside.

created at:12-13-2021
edited at: 12-13-2021: