您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)Springboot中靜態(tài)文件的引入方式有哪些的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來(lái)看看吧。
<!-- 渲染靜態(tài)頁(yè)面 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
如果你有
WebMvcConfigurationSupport 的一些類引用. 你需要放行他們
如果你引用了 springSecurity
你也需要放行他們
thymeleaf 需要通過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; } }
如果你想帶控制器也是可以的 (帶的話 指向index. 不帶的話 默認(rèn)指向index .可以理解成一個(gè)絕對(duì)路徑,一個(gè)相對(duì)路徑)
是為了能夠直接訪問 根目錄下的text文件
完成.
感謝各位的閱讀!關(guān)于“Springboot中靜態(tài)文件的引入方式有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。