Springboot

Springboot,第1张

Springboot

使用 Spring Boot + Spring MVC
编写一些代码时,我遇到了完全相同的问题。使用CDN设置的CSS文件运行良好,而我

static/css
文件夹中的CSS文件设置返回了HTML内容

例:

<!-- This first worked fine, loading all styles --><link th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"      href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/css/bootstrap.min.css"      rel="stylesheet" media="screen" /><!-- This second one returned the content of an HTML - Content Type text/html --><link rel="stylesheet" th:href="@{/css/login/style.css}" href="/css/login/style.css" />

一段时间后,我发现使用 Chrome开发工具 可以看到,本地返回的内容

style.css
与HTML页面之一相同。

检查指向具有该内容的HTML文件的路由,我可以意识到我在

@RequestMapping
配置中使用了错误的属性。我有
@RequestMapping(name="...")
,而不是
@RequestMapping(path="...")

控制器有问题

@RequestMapping(name = "/product/add", method = RequestMethod.GET)public String add(Model model) {    model.addAttribute("product", new Product());    return "product/edit";}

控制器已更改

@RequestMapping(path = "/product/add", method = RequestMethod.GET)public String add(Model model) {    model.addAttribute("product", new Product());    return "product/edit";}

更改属性后

name
path
所有内容均开始正确加载。

奇怪的是,这样的小错误如何影响了我的整个程序。

希望它对面临同样问题的人有所帮助。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4900685.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存