link CSS in a Spring MVC project

Asked

Viewed 151 times

0

Take a good look at the picture;

inserir a descrição da imagem aqui

I tried to put it on the page like this;

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" type="text/css"  href="resources/css/style.css/>

I tried that way too;

<link rel="stylesheet"  href="resources/css/style2.css/>

but didn’t get the CSS settings.

========UPDATING==============================

I tried that way too ;

<link rel="stylesheet"  href="resources.css/style.css/>
<link rel="stylesheet"  href="resources.css/style2.css/>

1 answer

1

In its Spring MVC configuration class extending the class Webmvcconfigureradapter, the method addResourceHandlers should be overwritten and left this way:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/views/resources/");
}

The first parameter "/resources/**" tells you which URL will access the static resources(css, js, img...), the second parameter tells you which folder the resources are in "/views/resources/"

Example:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.