用的是springboot
代码如下:
controller层
@Controller
public class freemarkerController {
@RequestMapping("/index")
public String freemarker(Model model){
model.addAttribute("class","数学");
return "index";
}
}
yml配置文件
freemarker:
suffix: .ftl
charset: utf-8
cache: false
template-loader-path: classpath:/templates/
在ftl页面上用${class}测试取值,结果报错,报错里有一行
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> class [in template "index.ftl" at line 47, column 3]
我想可能是class是空值的问题,然后加了判断空值${class?if_exists},就没有报错。。我想问哪里出问题了,代码跟着视频敲得