Springboot中靜態(tài)文件的兩種引入方式總結(jié)
thymeleaf 模式
依賴中引入
<!-- 渲染靜態(tài)頁(yè)面 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
可選配置
如果你有
WebMvcConfigurationSupport 的一些類引用. 你需要放行他們
如果你引用了 springSecurity
你也需要放行他們
thymeleaf 需要通過(guò)controller層轉(zhuǎn)向view 層
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; /** * @ClassName: * @Descripton: * @Author: sansy * @Date: 2019/5/16 10:12 * @Version: 2.0 */ @RestController public class IndexController { @RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView index() { System.out.println("/index進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } @RequestMapping(value = "/home", method = RequestMethod.GET) public ModelAndView home() { System.out.println("/home進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } @RequestMapping(value = "/error", method = RequestMethod.GET) public ModelAndView error() { System.out.println("/error進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } @RequestMapping(value = "/login", method = RequestMethod.GET) public ModelAndView login() { System.out.println("/login進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } @RequestMapping(value = "/", method = RequestMethod.GET) public ModelAndView indexs() { System.out.println("/ 進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } @RequestMapping(value = "/404", method = RequestMethod.GET) public ModelAndView error404() { System.out.println("/404 進(jìn)入controller控制器"); ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } }
yml 做如下配置
構(gòu)架這樣構(gòu)架
非thymeleaf 模式
首先去掉依賴
刪除controller的指向view層
如果你想帶控制器也是可以的 (帶的話 指向index. 不帶的話 默認(rèn)指向index .可以理解成一個(gè)絕對(duì)路徑,一個(gè)相對(duì)路徑)
yml文件中這樣配置
是為了能夠直接訪問(wèn) 根目錄下的text文件
構(gòu)架如下
完成.
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java中JDBC實(shí)現(xiàn)往MySQL插入百萬(wàn)級(jí)數(shù)據(jù)的實(shí)例代碼
這篇文章主要介紹了java中JDBC實(shí)現(xiàn)往MySQL插入百萬(wàn)級(jí)數(shù)據(jù)的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-01-01聊聊BeanUtils.copyProperties和clone()方法的區(qū)別
這篇文章主要介紹了聊聊BeanUtils.copyProperties和clone()方法的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09Java整合mybatis實(shí)現(xiàn)過(guò)濾數(shù)據(jù)
這篇文章主要介紹了Java整合mybatis實(shí)現(xiàn)過(guò)濾數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-01-01Java中dubbo+zookeeper微服務(wù)架構(gòu)簡(jiǎn)介
Apache Dubbo是一款高性能的 Java RPC 框架,這篇文章主要介紹了Java中dubbo+zookeeper微服務(wù)架構(gòu),需要的朋友可以參考下2021-09-09使用springboot logback動(dòng)態(tài)獲取application的配置項(xiàng)
這篇文章主要介紹了使用springboot logback動(dòng)態(tài)獲取application的配置項(xiàng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08java通過(guò)釘釘機(jī)器人發(fā)消息的實(shí)現(xiàn)示例
本文主要介紹了java通過(guò)釘釘機(jī)器人發(fā)消息的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09