我正在使用 Spring Boot 3.3.0 创建一个 Spring Boot 应用程序。我已将我的实体放置在主应用程序包下名为“entities”的包中,而控制器位于主应用程序包内名为“controllers”的包中。
当我尝试访问任何控制器端点时,收到 404 错误;例如,当点击 localhost:8080/account-types/create 时,返回的错误是“出现意外错误(type=Not Found,status=404)。没有静态资源 account-types/account_type_create。”
模板: HTML 模板
控制器方法: 控制器方法
您的代码中的一切都正确。如果您添加
thymeleaf
依赖项,它将起作用。对于 gradle 来说是
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
对于行家
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>