我有一个相当神秘的想法,我不知道从哪里开始搜索,或者是为了什么。问题是,我的编辑页面为选定的项目不加载css,而几乎相同的页面,添加相同的项目加载很好。我去用diff check检查差异,只是为了确认一下,但我找不到它。有没有可能,因为它是项目的/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>发布于 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。)
https://stackoverflow.com/questions/42782904
复制相似问题