SpringBoot+thymeleaf出现[THYMELEAF][http-nio-8080-exec-1] An error happened during template parsing

就离了大谱,一直出现这个错误,找了半天错误,就是没有想到最简单的拼写错误。就是说,有错了咱一定要仔细看报错信息,ok?

以下是我的报错内容

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]")

在这个位置继续向下看!!!有很明显的caused by,此处的是导致出现以上错误的原因。我的原因如下:

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?

这个错误的意思是 “createTime” 这个属性找不到(要么是你没有这个属性值,要么是你这此处拼写错误)
出现以上的错误呢,首先去相对应的html文件中找到报错的位置,然后找到对应的javaBean,查看拼写是否写错。修改成正确属性名,重新编译 错误消失。

我的controller层:

@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<>();
                map.put("post",post);
                User user = userService.findUserId(post.getUserId());
                map.put("user",user);
                discussPosts.add(map);
            }
        }
        model.addAttribute("discussPosts",discussPosts);
        return "index";
    }

我的index.html部分内容

<!-- 帖子列表 -->
				<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="用户头像" style="width:50px;height:50px;">
							</a>
						<div class="media-body">
							<h6 class="mt-0 mb-3">
								<a href="#"  th:utext="${map.post.title}">备战春招,面试刷题跟他复习,一个月全搞定!</a>
								<span class="badge badge-secondary bg-primary" th:if="${map.post.type==1}">置顶</span>
								<span class="badge badge-secondary bg-danger" th:if="${map.post.status==1}">精华</span>
							</h6>
							<div class="text-muted font-size-12">
								<u class="mr-3" th:utext="${map.user.name}">寒江雪</u> 发布于 <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">赞 11</li>
									<li class="d-inline ml-2">|</li>
									<li class="d-inline ml-2">回帖 7</li>
								</ul>
							</div>
						</div>						
					</li>
				</ul>

报错的地方时 map.post.createTime 中createTime不可用,然后我找到对应post类,即DiscussPost,其属性定义如下

   private Date creatTime;

两者不一致,修改一致后重新运行,错误消失,成功呈现效果页面。

注意:
假如不是拼写错误,再去尝试其他的解决办法,可参考此博客

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值