从数据库中显示来自URL的图像。

huangapple go评论77阅读模式
英文:

Display images from url in database

问题

我有一个MySQL数据库在一个表中存储着指向位于AWS S3上的图像的链接这些图像在数据库中与特定注册用户关联

我需要展示这些图像每行3张照片),其链接在我的数据库中也就是说当我添加一个链接时我需要这个图像出现在页面上

在程序中我使用JavaSpringThymeleafHTML用于显示页面)。

提前感谢大家

![数据库中的表截图][1]


  [1]: https://i.stack.imgur.com/RBKwq.png


图像实体类

    @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 + '\'' +
                '}';
    }
    }
英文:

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!

从数据库中显示来自URL的图像。

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

答案1

得分: 1

有许多方法可以实现此功能,但最终您需要将图像网址传递给浏览器,并使用 HTML 的 <img> 标签来显示图像。

关于如何获取图像网址,也有许多方法。您可以使用 Ajax,因此这更多涉及 JavaScript 技术。

如果您正在使用 Thymeleaf,这更多涉及服务器端处理,您需要在 Thymeleaf 模板中编写显示逻辑,一旦浏览器获得 HTML 结果,您的图像将自动显示。

英文:

There are many ways to do so, but ultimately you need to pass your image url to your browser and you use html &lt;img&gt; 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.

huangapple
  • 本文由 发表于 2020年9月29日 21:00:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64120175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定