[THYMELEAF][http-nio-8080-exec-1] An error happened during template parsing

created at 06-19-2022 views: 4


2022-06-13 15:22:24.903 ERROR 111252 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")

Keep looking down at this location! ! ! There is an obvious caused by, here is the reason for the above error. My reasons are as follows:

Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "#dates.format(map.post.createTime,'yyyy-MM-dd HH:mm:ss')" (template: "index" - line 132, col 68)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#dates.format(map.post.createTime,'yyyy-MM-dd HH:mm:ss')" (template: "index" - line 132, col 68)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'createTime' cannot be found on object of type 'com.nowcoder.community.entity.DiscussPost' - maybe not public or not valid?


This error means that the property createTime cannot be found (either you don't have a value for this property, or you have spelled it wrong here)

If the above error occurs, first go to the corresponding html file to find the location of the error, and then find the corresponding javaBean to check whether the spelling is wrong. Modify it to the correct attribute name, and recompile the error will disappear.


@RequestMapping(path = "/index",method = RequestMethod.GET)
    public String getIndexPage(Model model){
       List<DiscussPost> list =  discussPostService.findDiscussPosts(0,0,10);
        List<Map<String,Object>> discussPosts  = new ArrayList<>();
        if (list!=null){
            for (DiscussPost post:list){
                Map<String,Object> map = new HashMap<>();
                User user = userService.findUserId(post.getUserId());
        return "index";

part of index.html

<!-- post list -->
<ul class="list-unstyled">
  <li class="media pb-3 pt-3 mb-3 border-bottom" th:each="map:${discussPosts}">
    <a href="site/profile.html">
        <img th:src="${map.user.headerUrl}" class="mr-4 rounded-circle" alt="User Avatar" style="width:50px;height:50px;">
    <div class="media-body">
    <h6 class="mt-0 mb-3">
      <a href="#" th:utext="${map.post.title}">xxxx</a>
      <span class="badge badge-secondary bg-primary" th:if="${map.post.type==1}">top</span>
      <span class="badge badge-secondary bg-danger" th:if="${map.post.status==1}">Best</span>
      <div class="text-muted font-size-12">
          <u class="mr-3" th:utext="${map.user.name}">xxx</u> Posted in <b th:text="${#dates.format(map.post.createTime ,'yyyy-MM-dd HH:mm:ss')}">2019-04-15 15:32:18</b>
        <ul class="d-inline float-right">
          <li class="d-inline ml-2">Like 11</li>
          <li class="d-inline ml-2">|</li>
          <li class="d-inline ml-2">Reply 7</li>

When the error is reported, createTime in map.post.createTime is not available, and then I find the corresponding post class, namely DiscussPost, whose properties are defined as follows

private Date creatTime;

The two are inconsistent, re-run after the modification is consistent, the error disappears, and the effect page is successfully rendered.

created at:06-19-2022
edited at: 06-19-2022: