跟着视频学freemarker,写了一段测试代码结果出现问题

用的是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},就没有报错。。我想问哪里出问题了,代码跟着视频敲得

应该是controller写的有问题,我在index页放了一个a标签跳转到一个新的页面,在新的页面上${class}可以取到值,那这样index页面没法用freemarker取值的问题该怎么解决(或者我之前这个controller错在哪了)

你把模板贴出来,看看,这个报错信息很明显,这个位置 line 47, column 3,你在仔细看看是不是语法错误

class 你换个其他的名字 比如 aaa 然后 ${aaa} 试一下 先排除 class 是关键字的错误