简体   繁体   English

在数据库中显示来自 url 的图像

[英]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.我有一个 MySQL 数据库,在一个表中我存储了一个指向位于 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.我需要显示图像(连续 3 张照片),其链接在我的数据库中。 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).在程序中我使用 Java、Spring、Thymeleaf、HTML(用于显示页面)。

Thanks in advance to everyone!在此先感谢大家!

数据库表的截图

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 + '\'' +
            '}';
}
}

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.有很多方法可以做到这一点,但最终您需要将图像 url 传递到浏览器,并使用 html <img>标签来显示图像。

For how to get the image url, there are many ways too.获取图片url的方法也有很多种。 You can use ajax, hence this is more on Javascript technique.您可以使用 ajax,因此这更多的是关于 Javascript 技术。

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.如果您使用Thymeleaf ,这更多是在服务器端处理,您需要在Thymeleaf模板中编写您的显示逻辑,一旦浏览器得到 html 结果,您的图像将自动显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM