如何使用 vaadin 在我的 UI 中显示图片

How to show pictures in my UI working with vaadin

我只是想在 vaadin 布局中显示图片,我正在使用 vaadin 13。

我不确定问题出在哪里。我检查了很多次我的图片路径以及它是否在正确的包中,但一切似乎都是正确的。 所以我不明白为什么它不显示我的照片。

@SuppressWarnings("serial")
@Route(value = "", layout = MainView.class)
public class Overview extends VerticalLayout {

public Overview() {
    Label helloLabel = new Label("Hello User!");

    // Html img = new Html("<img src='/images/homePicture.jpg'>");
    // add(img);
    Image i = new Image("images/homePicture.jpg", "Alternative image text");
    add(i);


    Button secondButton = new Button("show");
    Dialog dialog = new Dialog();
    dialog.add(i);
    secondButton.addClickListener(event -> dialog.open());
    add(secondButton);

实际上它看起来像那样。

文件路径结构:

感谢@KasparScherrer

问题已解决

当我将 src/main/resources 文件夹更改为 src/main/webapp 时,它起作用了,但是我的 Maven 项目告诉我我的项目缺少所需的 src/main/resources 文件夹。