gpt4 book ai didi

java - Spring CSS 有时会加载 bootstrap 而不是我的 CSS

转载 作者:行者123 更新时间:2023-11-28 04:09:31 24 4
gpt4 key购买 nike

我很困惑,我不知道从哪里开始搜索或搜索什么。问题是我对所选元素的编辑页面没有加载 css,而实际上用于添加相同元素的相同页面加载得很好。我去用 diff check 检查差异只是为了确定,但我找不到它。是否有可能因为元素的/id 以某种方式未加载 CSS?

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

Controller 添加部分:

    @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;
}

Controller 编辑部分:

@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):

<!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):

<!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>

最佳答案

是的,它在编辑时在错误的页面中查找您的 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。)

关于java - Spring CSS 有时会加载 bootstrap 而不是我的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42782904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com