SpringBoot项目访问网页空白页报错:Whitelabel Error PageThis application has no explicit mapping for /error

报错信息

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sat Feb 29 16:42:04 CST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
在这里插入图片描述

方法1:看是否在\src\test\java\com\example\demo目录下创建了controller包,在controller包里创建Controller类

在这里插入图片描述

方法2:是否正确编辑DemoApplicationTests类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplicationTests {
    public static void main(String[] args){
        SpringApplication.run(DemoApplicationTests.class, args);
    }
}

在这里插入图片描述

方法三:是否地址输入错误

http://localhost:8080/test

这里的“/test”取决于HelloController类中 @RequestMapping("/test") 引号里的内容!
在这里插入图片描述

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/test")
    public String hello(){
        return "hello world!"; 
    }
}

以上是针对我本人在学习过程中遇到的问题,方法不够全面,也可能是其他的原因。

发布了9 篇原创文章 · 获赞 1 · 访问量 458

猜你喜欢

转载自blog.csdn.net/cMengZ/article/details/104578558