美文网首页
springboot静态资源的访问

springboot静态资源的访问

作者: 老张家的独苗 | 来源:发表于2017-06-14 08:29 被阅读0次

1.场景还原

由于公司项目是springboot构建的,访问静态资源必须是首要的考虑;但是springboot访问静态资源跟ssm中有些不一样的地方, 今天笔者就讲解一下在springboot工程中如何加载静态资源。

2.实现方案

方案①:直接地址栏访问

在工程的resources目录下新建static目录,将待访问的静态资源放进去

方案②:通过后台controller实现前端页面跳转

1>在pom.xml中加入velocity依赖( 模板引擎)

org.springframework.bootspring-boot-starter-velocity

2>在application.properities配置

spring.velocity.suffix=.html

3.在resources新建static,templates目录

static目录放静态文件(js,css,image之类),templates放模板文件(html,jsp)

注意:templates命名必须正确,里面的html中的资源引用不变,原前端工程怎么放就怎么放,资源路径写成未导入后端之前的样子

好了,访问效果:

大功告成,springboot的静态资源加载就说到这里了,我是张星,欢迎加入博主的技术交流群,群号:313145288

csdn博客链接:http://blog.csdn.net/zhangxing52077/article/details/73194948

相关文章

网友评论

      本文标题:springboot静态资源的访问

      本文链接:https://www.haomeiwen.com/subject/nhqsqxtx.html