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