简体   繁体   English

o:在数据库中删除或更新实际图像时,graphicImage不会更改

[英]o:graphicImage does not change when actual image is deleted or updated in database

I am trying to display a which is stored in a database. 我正在尝试显示存储在数据库中的内容。 I have a <o:graphicImage value="#{image.getById(1)}" /> . 我有一个<o:graphicImage value="#{image.getById(1)}" />

Note: The ID (1) is only for testing. 注意:ID(1)仅用于测试。

My property looks like: 我的财产看起来像:

@Lob
private byte[] image;

and my dao/service is this: 我的dao /服务是这样的:

@Name
@ApplicationScoped
public class Images {

    @Inject
    private UserDAO userDAO;

    public byte[] getById(int id) {
        return userDAO.getUserByID(id).getImage();
    }

To the concrete problem: 针对具体问题:

I just implemented this and the image is displayed correctly. 我刚刚实现了这一点,图像显示正确。 I set the image manually to NULL in the database. 我在数据库中手动将图像设置为NULL

My assumption: The image is not found and the image is not displayed (or the typical 'image is not found'-image.). 我的假设:没有找到图像,也没有显示图像(或者没有找到典型的“图像”图像)。

But: The old image is displayed. 但是:显示旧图像。 Even after a restart of the server and a clean. 即使重新启动服务器并清理干净。 Nothing changed. 没有改变。 I tried to upload an other image to the database - same result. 我试图将其他图像上传到数据库 - 结果相同。

What is the problem here? 这里有什么问题? Where is my fault? 我的错在哪里? How can I fix this? 我怎样才能解决这个问题?

The image is being cached by the client. 客户端正在缓存该映像。 The <o:graphicImage> is very effective in this. <o:graphicImage>在这方面非常有效。

You basically need to clean the browser cache, or to perform a forced reload in browser, or open an incognito window. 您基本上需要清理浏览器缓存,或在浏览器中执行强制重新加载,或打开隐身窗口。

One way to avoid this is to include the image's "last modified" timestamp in the lastModified attribute, which can be either a java.util.Date , or a java.lang.Long representing the epoch time. 避免这种情况的一种方法是在lastModified属性中包含图像的“最后修改”时间戳,该属性可以是java.util.Date ,也可以是表示纪元时间的java.lang.Long Best is to add this property to your entity. 最好是将此属性添加到您的实体。

<o:graphicImage ... lastModified="#{image.lastModified}" />

It will ultimately end up as v= request parameter in the generated image URL, hereby tricking the browser cache when it changes. 它最终会在生成的图像URL中以v= request参数结束,从而在浏览器缓存发生变化时欺骗它。

Another way is to just change image's ID in method argument. 另一种方法是在方法参数中更改图像的ID。 It's in that perspective also a bit strange if you still keep providing the old image ID in the HTML response while this ID doesn't exist in the database anymore. 如果你仍然继续在HTML响应中提供旧的图像ID,那么这个视角也有点奇怪,而这个ID在数据库中不再存在。

See also: 也可以看看:

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

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