Spring Boot无法映射我的HTML文件
因此,我基本上有这个控制器:
package com.example.controllor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Controllors {
@RequestMapping("/")
public String index(){
return "index";
}
@RequestMapping("/login")
public String login(){
return "login";
}
@RequestMapping("/register")
public String register(){
return "register";
}
}
我得到了那些HTML页面: 这些3张图像
index html html工作正常,但登录。 。 (它说Whitelabel错误页面此应用程序没有明确的映射 /错误,因此您将其视为后备。SunJun
12 02:37:23 CEST CEST 2022 2022 出乎意料的错误(type =找不到,状态= 404)。 )
有帮助吗?我失去了
胸腺宣言
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
So basically i got this controller :
package com.example.controllor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Controllors {
@RequestMapping("/")
public String index(){
return "index";
}
@RequestMapping("/login")
public String login(){
return "login";
}
@RequestMapping("/register")
public String register(){
return "register";
}
}
and i got those html pages :
these 3 images
the index html works fine but login.html and register.html don't work. (it says Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jun 12 02:37:23 CEST 2022
There was an unexpected error (type=Not Found, status=404). )
any help ? i'm lost
My Thymeleaf declaration
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于您的软件包结构。
由于您的主要类位于
com.example.demo
软件包中,因此Spring会将其视为基本软件包,并扫描其下面的所有子包bean。因此,您有两个选项
com.example.demo.controller
fackage。@springapplication
注释中,添加scanbasepackages
喜欢@springbootapplication(scanbasepackages =“ com.example”)
>The issue is in your package structure.
As your main class is in
com.example.demo
package, Spring will consider it as base package and scan all subpackages under it for beans.So, you have two options
com.example.demo.controller
package.@SpringApplication
annotation, addscanBasePackages
like@SpringBootApplication(scanBasePackages = "com.example")