我有一点点谜,我不知道从哪里开始搜索或者为了什么。问题是我的所选项目的编辑页面没有加载css,而添加相同项目的几乎相同的页面加载就好了。我去检查与差异检查的差异只是为了确保我找不到它。有可能,因为它是/ id的项目,某种方式CSS没有加载?
更清楚。在编辑页面上,Bootstrap会加载但我的CSS却没有。如果需要,请告诉我是否需要提供图片。
控制器添加部分:
@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;
}
控制器编辑部分:
@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>
答案 0 :(得分:0)
是的,它正在编辑时在错误的页面中查找您的CSS(因为编辑时网址中有额外的/
:
在/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。)