Thyemleaf报错: Method call: Attempted to call method *** on null context object

翻译:方法调用:尝试在null上下文对象上调用方法***

解释:在Thyemleaf上下中不存在所要调用的对象,相当于Java代码中的NullPointerException


解决方案:

方案1. 需要将期望调用的java实例存入thymeleaf的context域中,代码层面即为:将实例对象存入Request对象中。

示例:
Java代码:
httpServletRequest.setAttribute("commons", commons);//一些工具类和公共方法

Thyemleaf表达式:
${commons.fmtdate_en(archive.created)}

方案2. thyemleaf表达式改变一下写法

${T(com.juyss.utils.Commons).fmtdate_en(archive.created)}
${T(要调用的类的全类名).要调用的方法}
原文地址:https://www.cnblogs.com/shmebluk/p/14184110.html