美文网首页
Springboot配置context-path静态支援找不到的

Springboot配置context-path静态支援找不到的

作者: 通通小小通 | 来源:发表于2020-03-27 13:16 被阅读0次
  • 今天配置了context-path项目路径却发现静态文件找不到了
    <link rel="stylesheet" href="/static/common/layuiadmin/layui/css/layui.css" media="all">

上面是没配置之前的静态文件路径

  • 直接说解决办法吧,不墨迹了
freemarker:
    suffix: .ftl
    template-loader-path: classpath:/templates/
    charset: UTF-8
    cache: false
    # 这一行配置是关键,先在配置文件里配置request-context-attribute
    request-context-attribute: request
  • 配置静态页面,在页面的第一行加入如下代码
    <#assign base=request.contextPath />
  • 然后在<head>标签里放入如下代码
    <base id="base" href="${base}">
  • 最后找到引用的静态文件加入如下代码
    <link rel="stylesheet" href="${base}/static/common/layuiadmin/layui/css/layui.css" media="all">

奇迹是不是发生了?

相关文章

网友评论

      本文标题:Springboot配置context-path静态支援找不到的

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