Ihor Mokrytskyi
Ihor Mokrytskyi

Reputation: 11

Display images from url in database

I have a MySQL database, in a table I store a link to an image that is located on AWS S3. This images in the database is tied to a specific user who registered.

I need to display images (3 photos in a row), the links of which are in my database. That is, when I add a link, I need this image to be added to the page.

In the program I use Java, Spring, Thymeleaf, HTML (for displaying pages).

Thanks in advance to everyone!

Screenshot of the table in database

Image Entity

@Entity
@Getter
@Setter
@Table(name = "image")
public class Image {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;

@Column(name = "image_link")
private String imageLink;

public Image() {
}

@Override
public String toString() {
    return "Image{" +
            "id=" + id +
            ", imageLink='" + imageLink + '\'' +
            '}';
}
}

Upvotes: 1

Views: 355

Answers (1)

Sam YC
Sam YC

Reputation: 11627

There are many ways to do so, but ultimately you need to pass your image url to your browser and you use html <img> tag to display the image.

For how to get the image url, there are many ways too. You can use ajax, hence this is more on Javascript technique.

If you using Thymeleaf, this is more on server side processing, you need to write your display logic in the Thymeleaf template, once browser got the html result, your image will be displayed automatically.

Upvotes: 1

Related Questions