Springboot 加载静态资源 404问题

2018-11-12  本文已影响0人  yfmei

springboot 工程

目录结构

├─static
      ├─css
      └─js
└─templates
# 应用上下文配置
server.servlet.context-path=/myprojectname

# 默认配置会自动在 /public /static /resources 目录寻找静态资源, 故不需要 /static 等前缀
spring.mvc.static-path-pattern=/**

# SpringMvc(ModelAndView) 视图前缀 prefix/xxx/xxx.html, 可不设,如果static目录下有以工程名命名的文件夹,则可以设置(如: /static/project/css)
spring.mvc.view.prefix=${server.servlet.context-path}

html 引用静态文件

```
<link href="/myprojectname/css/bootstrap.css" rel="stylesheet">
<script src="/myprojectname/js/jquery.js">
```

静态资源404问题总结

<link href="/myprojectname/css/bootstrap.css" rel="stylesheet">
上一篇 下一篇

猜你喜欢

热点阅读