【问题标题】:how add css,js in html files with spring mvc 4如何使用spring mvc 4在html文件中添加css,js
【发布时间】: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

my classpath

静态

@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控错误?

谢谢大家^^

【问题讨论】:

标签: css eclipse spring-mvc


【解决方案1】:

根据我以前的知识和错误,请确保您定义了正确的目录并添加了正确的链接。希望对您有所帮助,如果不是我很抱歉。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    相关资源
    最近更新 更多