J'utilise Spring MVC et le moteur de vue Thymeleaf. J'ai un externe style.css fichier avec le CSS pour ma page. Dans le fichier CSS, je veux faire référence à une URL d'image relative.Expression d'URL Thymeleaf dans le fichier .css
Ceci est mon style.css fichier:
.background {
width: 100%;
background-image: url('/path/to/image/bg.png');
}
Les ci-dessus tente d'accéder à une image avec l'URL suivante, qui n'existe pas:
http://localhost/path/to/image/bg.png
Mon vrai l'image est à:
http://localhost/myapp/path/to/image/bg.png
Cette question StackOverflow donne la réponse à ma question pour CSS en ligne: How to set background url for css files in thymeleaf?
Mais comment faire pour un fichier .css externe?