Springboot訪(fǎng)問(wèn)templates html頁(yè)面過(guò)程詳解
springboot項(xiàng)目默認(rèn)是不允許直接訪(fǎng)問(wèn)templates下的文件的,是受保護(hù)的。
如果要訪(fǎng)問(wèn)templates下的文件,推薦使用thymeleaf。
注:使用thymeleaf這一點(diǎn)要牢牢記住!
如何使用:
1、pom依賴(lài)
<!--thymeleaf 模板依賴(lài)--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2、配置文件
#模板熱部署、禁用 thymeleaf 緩存spring.thymeleaf.cache=false
3、html文件位于resources的templates/目錄下,例如
注意html文件名,這里使用goodsShow,在不區(qū)分大小寫(xiě)的情況下與后臺(tái)返回字符串匹配
4、后臺(tái)返回字符串形式訪(fǎng)問(wèn)html(也可以使用ModelAndView,這里不做展示)
@Controller@RequestMapping('/goods')public class GoodsController { private static final Logger log = LoggerFactory.getLogger(GoodsController.class); @GetMapping public String goodsShow() { return 'goodsShow'; }}
5、瀏覽器訪(fǎng)問(wèn)輸入:ip:端口號(hào)/上下文根/goods
本地訪(fǎng)問(wèn):localhost:端口號(hào)/上下文根/goods
例如:localhost:8080/goods
6、具體項(xiàng)目可以參考:https://github.com/guocanzhen/jQueryAjaxJavaWeb
里面還附有jQuery AJAX在springboot中的應(yīng)用。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. vue style width a href動(dòng)態(tài)拼接問(wèn)題的解決2. Java源碼解析之接口List3. 在vue中獲取wangeditor的html和text的操作4. python mysql 字段與關(guān)鍵字沖突的解決方式5. Python用K-means聚類(lèi)算法進(jìn)行客戶(hù)分群的實(shí)現(xiàn)6. Java xml數(shù)據(jù)格式返回實(shí)現(xiàn)操作7. python編寫(xiě)五子棋游戲8. 解決Android Studio Design界面不顯示layout控件的問(wèn)題9. 使用vue-cli創(chuàng)建項(xiàng)目并webpack打包的操作方法10. python讀取中文路徑時(shí)出錯(cuò)(2種解決方案)
