小编ge1*_*023的帖子

当我构建 Spring Boot 的 Web 项目时,我无法使用 freemarker

我的请求可以进入我的Welcomecontroller的方法,但似乎该方法无法返回freemarker页面给我或者spring boot没有区分freemarker(我已将.ftl文件放入/resources/templates/)

当我输入网址http://localhost:8080/index时

我从 chrome 中得到了这个,并且在 IDEA 的控制台中没有报告任何错误:

Whitelabel 错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。

2020 年 1 月 4 日星期六 22:52:53 CST 出现意外错误(类型=未找到,状态=404)。没有可用的消息

我的代码如下:

@Controller
public class WelcomeController {

    @Value("${application.message}")
    private String message;

    @GetMapping("/index")
    public String welcome(Map<String, Object> model) {
        model.put("time", new Date());
        model.put("message", this.message);
        return "welcome";
    }
}
Run Code Online (Sandbox Code Playgroud)
@SpringBootApplication
public class QuestionsiteApplication {
    public static void main(String[] args) {
        SpringApplication.run(QuestionsiteApplication.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

欢迎.ftl:

<!DOCTYPE html>
<html lang="en">
<body>
    Date: ${time?date}
    <br>
    Time: ${time?time}
    <br>
    Message: ${message}
</body>
</html> …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat freemarker spring-boot

0
推荐指数
1
解决办法
2672
查看次数

标签 统计

freemarker ×1

java ×1

spring ×1

spring-boot ×1

tomcat ×1