Thymeleaf异常-循环获取未定义属性报错

Thymeleaf异常-循环内获取未定义的属性

报错:
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: “node.dealReviewed”
原因:
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field ‘dealReviewed’ cannot be found on object of type ‘com.alibaba.fastjson.JSONObject’

问题

<ul class="mui-table-view" th:each="node:${data.nodeList}">
	<li class="mui-table-view-cell">
		<div class="audit col">
			<span class="audit-title" th:text="${node.name}">指导老师审批</span>
			<div class="audit-text left-sb">
				<span class="left-text">审批结果</span>
                <span class="right-state1" th:if="${node.dealReviewed} !=null"  th:text="${node.dealReviewed.reviewedStateStr}" >通过</span>
                <span class="right-state1" th:if="${node.dealReviewed} ==null"  ></span>
			</div>
			<div class="audit-text left-sb" th:if="${node.dealReviewed} !=null" >
				<span class="left-text">审批时间</span>
				<span class="right-text" th:text="${node.dealReviewed.reviewedDate}">2019-04-19 08:12:25</span>
			</div>
			<div class="audit-text left-sb" th:if="${node.dealReviewed} !=null">
				<span class="left-text">审批意见</span>
		<span class="right-text" th:text="${node.dealReviewed.reviewedDate}"></span>
			</div>
		</div>
	</li>
</ul>

原因分析

是因为我在后端传递 nodeList 的时候, node里面没有dealReviewed 这个属性
我的本意是没有这个属性,我就判断是否为空,如果为空,下面的就不显示
结果在使用的时候直接就报错了

解决方案

应该改为:   ${node.get('dealReviewed')}
可以看下面代码,能够直接运行的了
<ul class="mui-table-view" th:each="node:${data.nodeList}">
	<li class="mui-table-view-cell">
		<div class="audit col">
			<span class="audit-title" th:text="${node.name}">指导老师审批</span>
			<div class="audit-text left-sb">
				<span class="left-text">审批结果</span>
                <span class="right-state1" th:if="${node.get('dealReviewed')} !=null"  th:text="${node.dealReviewed.reviewedStateStr}" >通过</span>
                <span class="right-state1" th:if="${node.get('dealReviewed')} ==null"  ></span>
			</div>
			<div class="audit-text left-sb" th:if="${node.get('dealReviewed')} !=null" >
				<span class="left-text">审批时间</span>
				<span class="right-text" th:text="${node.dealReviewed.reviewedDate}">2019-04-19 08:12:25</span>
			</div>
			<div class="audit-text left-sb" th:if="${node.get('dealReviewed')} !=null">
				<span class="left-text">审批意见</span>
		<span class="right-text" th:text="${node.dealReviewed.reviewedDate}"></span>
			</div>
		</div>
	</li>
</ul>

好了,问题完美解决!

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值