我想创建一个简单的页面,其中vaadin的网格将与数据库中的数据一起显示。不幸的是,我没有在文档或电影中找到任何解决方案……所以,我有我的JPA课程:
@Entity
@Table
public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String movieName;
@Column
private String description;
public Movie(){}
public Movie(String movieName, String description) {
this.movieName = movieName;
this.description = description;
}
所有吸气剂和吸气剂。现在我要创建GUI:
@Route("show-movies")
public class MovieGUI extends VerticalLayout{}
我尝试了所有操作:Grid
答案 0 :(得分:1)
遵循以下原则:
@Route("show-movies")
public class MovieGUI extends VerticalLayout{
MovieGUI(MovieRepository repo) {
Grid<Movie> movieGrid = new Grid<>();
movieGrid.setItems(repo.findAll());
movieGrid.addColumn(Movie::getName).setHeader("Name");
movieGrid.addColumn(Movie::getDescription).setHeader("Description");
movieGrid.addComponentColumn(movie -> new NativeButton("Action", click-> doSomething(movie)).setHeader("");
add(movieGrid);
}
}
在此处查看演示源以获取更多示例:https://vaadin.com/components/vaadin-grid/java-examples