SpringBoot 初接触之 404

1. 确认输入项目路径是否正确,如:http://localhost:8080/index,这里需要注意的是端口号的查看

2. 确认注解是否用对

在 Controller 层类上面使用的注解是 @RestController 而并非是 @Controller,或者是 @Controller + @ResponseBody;
详解:如果返回 String 或者 json 的话就直接类上用 @RestController;
   如果想要页面跳转的话,就使用 @Controller;
   如果只有在某方法上返回 json,其他方法跳转页面,则在类上添加 @Controller,在需要返回 String 和 json 的方法上添加 @ResponseBody 注解;

3. 确认导入项目注解的包地址是否正确

@RequestMapping("/index")
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
import org.springframework.web.bind.annotation.RestController;

4. 确认包路径是否正确

SpringBoot 注解 @SpringBootApplication 默认扫描当前类的同包以及子包下的类;
如:启动程序在包名 com.jd 下,则会查找所有 com.jd 下的文件以及 com.jd 下的所有子包里面的文件;

最后,感谢博主 林祥纤 的分享,来源地址:http://412887952-qq-com.iteye.com/blog/2347057

原文地址:https://www.cnblogs.com/yjq520/p/7692140.html