首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring CSS有时加载bootstrap,但不加载我的CSS

Spring CSS有时加载bootstrap,但不加载我的CSS
EN

Stack Overflow用户
提问于 2017-03-14 18:04:10
回答 1查看 224关注 0票数 0

我有一个相当神秘的想法,我不知道从哪里开始搜索,或者是为了什么。问题是,我的编辑页面为选定的项目不加载css,而几乎相同的页面,添加相同的项目加载很好。我去用diff check检查差异,只是为了确认一下,但我找不到它。有没有可能,因为它是项目的/id,不知何故CSS没有被加载?

说得更清楚些。在编辑页面上,Bootstrap可以加载,但我的CSS不会。如果需要,请告诉我是否需要提供图片。

控制器添加部件:

代码语言:javascript
复制
    @RequestMapping(value = "/newcontactor", method = RequestMethod.GET)
public ModelAndView contactorFormNew() {
    ModelAndView mav = new ModelAndView("ContactorFormNew");

    Contactor c = new Contactor();
    List<Manufacturer> miro = serviceManu.listManufacturers();

    mav.addObject("contactor", c);
    mav.addObject("listManufacturers", miro);
    return mav;
}

控制器编辑部件:

代码语言:javascript
复制
@RequestMapping(value = "/contactors/{id}", method = RequestMethod.GET)
public ModelAndView fuseForm(@PathVariable Integer id) {
    ModelAndView mav = new ModelAndView("ContactorForm");

    Contactor c = serviceContactor.getContactorById(id);

    List<Manufacturer> miro = serviceManu.listManufacturers();

    for (int i = 0; i < miro.size(); i++) {
        if (miro.get(i).getName().equals(c.getManufacturer().getName())) {
            miro.add(0, miro.get(i));
            miro.remove(i + 1);
        }
    }
    mav.addObject("contactor", c);
    mav.addObject("listManufacturers", miro);

    return mav;}

编辑html (不加载CSS):

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<title>Contactor Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="Style.css"></link>

</head>

添加html(加载css):

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<title>Contactor New</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="Style.css"></link>

</head>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-15 04:48:13

是的,它在编辑时在错误的页面中查找您的css (因为在编辑时url中有额外的/

/newcontactor上,它在/Style.css中查找CSS

/contactors/{id}上,它在/contactors/Style.css中查找CSS

我认为把<link rel="stylesheet" type="text/css" href="Style.css"></link>改成<link rel="stylesheet" type="text/css" th:href="@{/Style.css}"></link>应该能解决这个问题。(这稍微取决于您的上下文/servlet的设置方式。)

(您应该通过查看浏览器开发人员工具中的网络选项卡来调试这类东西。尝试加载Style.css时,网络选项卡将清楚地显示404。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42782904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档