【发布时间】:2017-09-20 12:18:07
【问题描述】:
我在使用 spring 4 导入 CSS 文件时遇到困难
首先我在 index.html 中尝试过这个
<link href="../../resources/css/bootstrap.min.css" rel="stylesheet">
Eclipse 没有确认任何错误,但是当我运行应用程序时,页面上没有加载 css
搜索后我做了这个
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
在 index.html 中,我就这样离开了它,它起作用了
<link href="resources/css/bootstrap.min.css" rel="stylesheet">
但是eclipse说有错误 look this
静态
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/*.html").addResourceLocations("/WEB-INF/html/");
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
super.addResourceHandlers(registry);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController( "/" ).setViewName( "forward:/index.html" );
}
1)导入CSS和JS以及spring 4的正确方法是什么?
2)为什么第一种方法不起作用?使用 ../../
3)如何导入时不出现eclipse控错误?
谢谢大家^^
【问题讨论】:
-
尝试使用
-
在这里你可以找到我的相同问题的答案:stackoverflow.com/a/53125816/9918701
标签: css eclipse spring-mvc