在控制器中设置了变量,但Thymeleaf无法正确呈现

时间:2019-05-02 17:12:53

标签: spring thymeleaf

我有以下代码...

@RequestMapping(value = "", method = RequestMethod.GET)
public String messages(Model model) {
    model.addAttribute("apikey", "test");
    return "index";
}
<link th:href="@{'https://maps.googleapis.com/maps/api/js?key=' + ${apikey}}" />

但是当我运行它时,我得到...

<link href="https://maps.googleapis.com/maps/api/js?key=null">

配置为...

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver
            = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/html/");
    viewResolver.setSuffix("");
    return viewResolver;
}

如何让它传递实际值?

更新

我将文件放在错误的文件夹中,因此我将html移至WEB-INF / html,但现在模板甚至无法呈现。

0 个答案:

没有答案