Thymeleaf踩雷之SpelEvaluationException: EL1007E: Property or field 'data' canno be found on null

问题:在使用Thymeleaf模板引擎绑定controller传来的对象时,报了个EL1007E的error !

控制台错误关键截取:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'data' cannot be found on null
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:58)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:111)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:334)
	at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
	... 90 common frames omitted

错误提示说:找不到data参数或者data为空!

其实只需要在前端获取值前判断一下非空就可以了!

如:


   

 

下面是我的问题解决过程!


 

废话少说!问题复盘:

1、在Controller中,我返回了resultVO对象。

model.addAttribute("resultVO",resultVO);

2、在前端我通过Thymeleaf模板获取。

结果报错EL1007E的错!这我就很郁闷了,因为我可以确定它是有值的!

所以我第一时间怀疑自己语法写错了,但我还是要先排除resultVO里的data参数为空这个可能!

3、前端改变,只获取到resultVO

结果没有令我失望! 可以看到data是有值的,这让我更加肯定是我语法问题了!

ResultVO(code=0, msg=商品正常, data=PageInfo{pageNum=1, pageSize=10, size=10, startRow=0, endRow=9, total=10, pages=1, list=[ProductVO(productId=112456464113213211, productName=凉风, productIcon=//546, productPrice=68.00, productStock=112, productDescription=运动、青春、爱情, productCategoryName=书籍, productCreatTime=2019-10-01 19:53:20, productUpdateTime=2019-10-29 05:11:44), ProductVO(productId=121244454578874125, productName=芝士汉堡, productIcon=//1233, productPrice=12.00, productStock=100, productDescription=香气扑鼻, productCategoryName=食品, productCreatTime=2019-10-01 19:48:21, productUpdateTime=2019-10-29 05:11:40),.............

 我又想到错误提示说我的值为空,我就猜想!试一下先判断下 resultVO 非空,排除值为空的可能!


   

结果发现前端可以正常显示了,控制台也不再报错了!问题解决!!!

你可能感兴趣的:(thymeleaf)