英文:
Display images from url in database
问题
我有一个MySQL数据库,在一个表中存储着指向位于AWS S3上的图像的链接。这些图像在数据库中与特定注册用户关联。
我需要展示这些图像(每行3张照片),其链接在我的数据库中。也就是说,当我添加一个链接时,我需要这个图像出现在页面上。
在程序中,我使用Java、Spring、Thymeleaf、HTML(用于显示页面)。
提前感谢大家!
![数据库中的表截图][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!
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 <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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论