报错信息
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!";
}
}