主要是注意項目結(jié)構(gòu),home.html放在src/resources/templates下的home.html下,application.properties可以不做任何配置。還有就是關(guān)于web包的位置,作者一開始將web包與tabtab包平行,訪問8080出現(xiàn)了此類報錯:
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.?
這里要注意創(chuàng)建springboot項目時指定了包名是tabtab,所以項目啟動時會自動掃描tabtab包,所以web包要放在tabtab包下。
HomeController代碼部分:文章來源:http://www.zghlxwxcb.cn/news/detail-663727.html
package com.example.tabtab.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/")
public String home() {
return "home";
}
}
處理對根路徑的請求即可,返回String類型的home值,解析為視圖的邏輯名,視圖如何實現(xiàn)取決于多個因素。文章來源地址http://www.zghlxwxcb.cn/news/detail-663727.html
到了這里,關(guān)于Tomcat運行后localhost:8080訪問自己編寫的網(wǎng)頁的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!