注:Springboot的版本2.1.3.RELEASEhtml
List-1 application.properties文件java
server.port=8080 #url中,項目的前綴 server.servlet.context-path=/project spring.mvc.view.prefix=/ spring.mvc.view.suffix=.html
總體結構以下圖1所示,html要放在static下,不是templates下web
圖1spring
List-2 HelloController的內容以下瀏覽器
import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Slf4j @Controller public class HelloController { @RequestMapping(value = "/hello") public String index() { log.info("收到請求"); return "html/hello"; } }
List-3 啓動springboot,以後在瀏覽器中輸入spring-mvc
#返回index.html的內容 http://localhost:8080/project/ #返回hello.html的內容 http://localhost:8080/project/hello
網上不少關於模板的(Thymeleaf 、FreeMarker 等),可是我不須要,我只須要純的html。springboot
index.html是springboot的默認welcome page。bash