在 Freemarker FTL 文件中,我想调用StringUtils.capatilize(myString)
。例如:
<p>You selected ${selectionString}.</p>
<p>${StringUtils.capatilize(selectionString)} is great.</p>
我可以以某种方式import org.apache.commons.lang3.StringUtils
?
首先,将这些代码添加到您的Controller
:
BeansWrapper wrapper = new BeansWrapper(new Version(2,3,27));
TemplateModel statics = wrapper.getStaticModels();
model.addAttribute("statics", statics);
然后,在你的.ftl
文件中,定义类如下:
<#assign YourUtilClass=statics['com.springboot.util.YourUtilClass']>
(该路径包括['']
是类的路径)
最后,您可以像这样访问静态方法:
${YourUtilClass.yourMethod(someParams)}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)