This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Dec 01 10:45:13 CST 2020
There was an unexpected error (type=Not Found, status=404).
跟着网上的教程来写自己的第一个Springboot项目时,发现出现过404,根据这个情况自己去找教程,然后做了一份图解。
自己创建的目录,方便理解。注意SpringbootApplication所在的包,它接管了同级和子目录的RestController,如果不满足这个条件,那么就会爆错。
first.java不在Springbootapplication.java的同级目录和其子目录下,所以报错。
package first;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class first {
@RequestMapping("/first")
public String hi(){
return "你好,检查Springboot启动项目录结构,成功";
}
}
second.java在Springbootapplication.java的同级目录和其子目录下,所以运行正常。
package first.second;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class second {
@RequestMapping("/second")
public String hi(){
return "你好,检查Springboot启动项目录结构,成功";
}
}
third.java在Springbootapplication.java的同级目录和其子目录下,所以运行正常。
package first.second.third;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class third {
@RequestMapping("/third")
public String hi(){
return "你好,检查Springboot启动项目录结构,成功";
}
}
所以Springbootapplication在那里可以随意一点,但是尽量在最外层,这样可以接管更多的东西。