今天在写项目的时候,突然发现引用js的时候路径不匹配,让我再次对路径问题产生了疑问,通过查阅springboot官网可以发现,在springboot中查找静态资源的时候,会默认在static、public、resources下查找,官网中也提出可以通过spring.web.resources.static-locations属性覆盖原来的默认行为,当我们想在访问静态资源的时候,要求访问路径有前缀则可以通过
spring.mvc.static-path-pattern设置。
![](https://img-blog.csdnimg.cn/direct/aa216f87fbee4f0fb68a874101186e47.png)
在项目中,使用thymeleaf渲染页面的时候,前端或者后端设置的路径=在访问页面时候的路径,例如第一个就是localhost:8080/js/jquery-1.10.2.min.js,当访问这个路径,springboot会通过默认查找静态资源规则,在static或者templates中寻找。
ps:如果设置了static-location则其他文件夹==原static文件夹,下图的路径不用改变。但是如果设置了path-pattern=ww,则下图中所有路径前面都要加'ww'。
![](https://img-blog.csdnimg.cn/direct/60439e12d69b482faddb3abc296ad2e5.png)
![](https://img-blog.csdnimg.cn/direct/31e2e2848f57489496b2aefb9a11ffb9.png)
controller层重定向:只有session中的值会存在,重定向回服务端controller层。
![](https://img-blog.csdnimg.cn/direct/a045c380849f40cdada444c08aa4284d.png)
controller层转发:session和request域中的值都会存在,转发回服务端controller层,接收传参map/model/request都可以设置request域
![](https://img-blog.csdnimg.cn/direct/19fe70efdd0a49eb9d1e074fc33aa6cd.png)