我正在练习我的springboot知识,所以我试着创建一个简单的待办事项应用程序。当我在localhost:8080/tasks/list运行我的主应用程序时,即使我为我的html文件配置了正确的路由,我也会得到一个白标签错误页面。我现在使用的是JSP,我也创建了一个thymeleaf版本,但我仍然会得到同样的错误。谢谢!
enter image description here
MainApp.java
package task.springboot.todo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TodoappOracleApplication {
public static void main(String[] args) {
SpringApplication.run(TodoappOracleApplication.class, args);
}
}
TaskController.java
package task.springboot.todo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/tasks")
public class TaskController {
@GetMapping("/list")
public String showTodoList() {
return "todo-list";
}
}
todo-list.jsp
<!DOCTYPE html>
<html>
<head>
<title> Todo Application </title>
</head>
<body>
<h2>Welcome to Todo Application</h2>
</body>
</html>
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.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>task.springboot.todo</groupId>
<artifactId>todoapp_oracle</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>todoapp_oracle</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
#
#
#
#
# Oracle Database Datasource
#
#
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=system
spring.datasource.password=password
#
#
#
#
1条答案
按热度按时间9udxz4iz1#
请将thymeleaf依赖项添加到
pom.xml
并将文件扩展名从
.jsp
更改为.html
(todo-list.html)
,并将其放在路径src/main/resources/templates
下