导入前端项目后,intellij  idea无法显示静态页面,报404错误,如图所示

(以我的一个html文件tjxs.html为例)

intellij idea无法显示静态页面,报404错误如何解决

解决方案:

在主目录main下的resources下新建两个文件夹,templates下存放html文件,static下存放css、js、img等文件

intellij idea无法显示静态页面,报404错误如何解决intellij idea无法显示静态页面,报404错误如何解决

在pom文件中添加web相关的依赖和Thymeleaf依赖

intellij idea无法显示静态页面,报404错误如何解决

intellij idea无法显示静态页面,报404错误如何解决

新建一个Controller类,用spring mvc的写法。因为SpringBoot集成了Thymeleaf,所以它会默认查找resources下面的templates这个目录下的文件。

intellij idea无法显示静态页面,报404错误如何解决

重新运行项目,在浏览器中输入localhost:8080/tjxs 回车看是否页面能够显示出来

(默认端口为8080,若你设置了其他的端口请使用你自己的端口)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2023-03-22
  • 2022-12-23
  • 2021-12-23
  • 2021-03-30
  • 2021-06-23
猜你喜欢
  • 2021-06-04
  • 2021-12-21
  • 2021-05-16
  • 2021-12-05
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
相关资源
相似解决方案