thymeleaf——th:value标签为空报错解决办法

需求

注:examidtpGlobalExammessage对象的属性

<form id="form-notice-edit" th:object="${tpGlobalExammessage}">
	<input  th:field="*{examid}"  type="hidden">
</form>

以上代码逻辑上面没有问题,但是当后台取到的tpGlobalExammessage对象为空时,由于examid同样为空则,程序会报错

EL1007E: Property or field 'examid' cannot be found on null

看了许多博客,发现了一个很神奇的办法,代码改为

 <form class="form-horizontal m" id="form-notice-edit" th:object="${tpGlobalExammessage}">
		 <input id="examid" name="examid" th:value="${tpGlobalExammessage?.examid}"  type="hidden">
 </form>

简单点说就是讲${tpGlobalExammessage.examid}改为${tpGlobalExammessage?.examid} 的取值方式,具体原因不清楚,加上之后examid为空则不影响程序的运行,同时当examid不为空时,此方式仍能渠道它的值
果断小本本记下,以备日后使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值