thymeleaf 报错解决EL1008E: Property or field ‘role_id’ cannot be found on object of type 'java.util.Hash
版权声明:本文原创文章,转载请附上原文出处链接和本声明。
本文链接:https://www.weijc.cn/jdetail/1588934954679
使用thymeleaf获取参数的时候报错:
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field ‘role_id’ cannot be found on object of type ‘java.util.HashMap’ - maybe not public or not valid?
th:text="${item.role_id}"
解决办法:
使用map的方式获取值,即使用 ${item.get(‘role_id’)} 替换 ${item.role_id}。
th:text="${item.get(‘role_id’)}"
优化处理:当item为空的情况
th:text="${item?.get(‘role_id’)}"