一、 新建一個空的Spring Boot項目後, 運行,打開瀏覽器,地址中輸入: Http://127.0.0.1:8080 二、 這時候報錯:java
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.web
Sun Dec 30 21:42:42 CST 2018 There was an unexpected error (type=Not Found, status=404). No message availablespring
三、 錯誤緣由是沒有添加 Controller類和方法。 在DemoApplication的同級目錄中添加類 HomeController,代碼以下:瀏覽器
package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HomeController { @RequestMapping("/") @ResponseBody public String index(){ return "Hello Spring Boot."; } }
四、 刷新頁面, 出現字符串:app
"Hello Spring Boot."this