栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Springboot

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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
所有内容均开始正确加载。

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

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/369404.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号