[我在构建Spring Boot的Web项目时无法使用freemarker

问题描述 投票:0回答:1
<<

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

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

Whitelabel错误页面此应用程序没有针对/ error的显式映射,因此您将其视为后备。[Sat Jan 04 22:52:53 CST 2020发生意外错误(类型=未找到,状态= 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"; } } @SpringBootApplication public class QuestionsiteApplication { public static void main(String[] args) { SpringApplication.run(QuestionsiteApplication.class, args); } }

welcome.ftl:

<!DOCTYPE html> <html lang="en"> <body> Date: ${time?date} <br> Time: ${time?time} <br> Message: ${message} </body> </html>

application.properties:

application.message: Hello, Andy

pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>cn.UU</groupId> <artifactId>questionsite</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>questionsite</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <commons-lang3-version>3.1</commons-lang3-version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

当输入URL http:// localhost:8080 / index时,我从chrome中获取了此信息,并且未在IDEA控制台中报告任何错误:Whitelabel Error Page此应用程序没有/ error的显式映射,...
java spring spring-boot tomcat freemarker
1个回答
0
投票
server: servlet: context-path: /cx
© www.soinside.com 2019 - 2024. All rights reserved.