Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

img not showing using Thymeleaf and Springboot

I am using thymeleaf along with springboot

I am not able to view any images in my HTML file. I have tried all different ways of doing the same in thymeleaf but no luck.

Here is my project folder structure

🗁 src
└─── 🗁 main
    └─── 🗁 resources
        ├─── 🗁 templates
        ├─── 🗁 css
        └─── 🗁 images

HTML File

<head>
    <title>Community Bike Share Web Application</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/3.1.1/css/bootstrap.min.css}" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
</head>

<div>
    <img th:src="@{/images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg}"
         src="../images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg" class="img-responsive" alt="Responsive image"/>
</div>
like image 496
komal dedhia Avatar asked Nov 19 '14 20:11

komal dedhia


People also ask

How do I display an image in Thymeleaf?

Thymeleaf Templatehtml in the path src/main/resources/templates. This template displays an HTML form to allow the user to select and upload an image. Furthermore, we use the accept=”image/*” attribute to allow users to import images only instead of importing any kind of files.

How do I enable Thymeleaf in Spring Boot?

1.1. Spring Boot will provide auto-configuration for Thymeleaf. Add spring-boot-starter-thymeleaf dependency in pom. xml to enable this auto-configuration. No other configurations required, Spring Boot will inject all required configuration to work with Thymeleaf.

How does Spring Boot Work With Thymeleaf?

It provides full integration with Spring Framework. It applies a set of transformations to template files in order to display data or text produced by the application. It is appropriate for serving XHTML/HTML5 in web applications. The goal of Thymeleaf is to provide a stylish and well-formed way of creating templates.


1 Answers

With Boot's default configuration, your images (and other static content), need to be beneath src/main/resources/static. For example, to serve content from /images put the files in src/main/resources/static/images

like image 195
Andy Wilkinson Avatar answered Oct 26 '22 17:10

Andy Wilkinson