Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback There was an unexpected error (type=Not Found, status=404).

今天创建了一个springboot项目后测试controller跳转页面发现一值报404错误

  • 在这里插入图片描述

创建的代码:

  • 在这里插入图片描述

  • 在这里插入图片描述

错误原因*

  • 在springboot中如果使用@Controller不加入模板技术的话,启动服务器不会报错,但是无法网页访问项目。

解决办法

  • pom文件中加入了模板thymeleaf依赖

  • 在这里插入图片描述

  •     <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    

    之后重启服务器就可以正常访问了

  • 在这里插入图片描述

总结:

在springboot中使用@RestController注解时候不需要模板技术;
但是如果使用@Controller注解不加入模板技术的话,启动服务器不会报错,但是无法网页访问项目。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐