当我像下面这样使用@RequestMapping时,我可以很好地渲染html
@RequestMapping("/demo")
public String news() {
return "demo";
}
但是当我添加参数@PathVariable("docid")时,它丢失了所有静态资源。
@RequestMapping("/single/{docid}")
public String single( @PathVariable("docid") String docid) {
return "demo";
}
在浏览器控制台中,显示无法加载资源:服务器以 404() 状态响应。
我使用localhost:8080/single/123要启动该页面,它将具有没有任何静态资源的 demo.html ,但是当我使用 localhost:8080/demo 时,效果很好。
我将import语句改为th:src="@{/js/my.js}",它仍然从localhost:8080/single/js/my.js搜索静态资源,我该怎么办?
Ps:我使用 Thymeleaf 作为模板。
最佳答案
使用 URL http://host:port/single/1001 ,并且您没有理由得到 404。请确保您在路径 (URL) 中使用 docid 值。
关于java - 使用@PathVariable时如何使用spring boot和thymeleaf在首页导入静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409109/