Thymeleaf踏雷のSpelEvaluationException:EL 1007 E:Property or field'data'canno be found on null

2808 ワード

質問:Thymeleafテンプレートエンジンを使用してcontrollerから送られてきたオブジェクトをバインドするときに、EL 1007 Eの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が空ではないと判断し、値が空の可能性を排除してみましょう.
その結果、フロントエンドが正常に表示され、コンソールも間違っていないことがわかりました.問題解決!!!