gpt4 book ai didi

java - 默认情况下将我的 JavaBean 的所有属性添加为 Vaadin 8 网格中的列?

转载 作者:行者123 更新时间:2023-12-01 16:49:19 25 4
gpt4 key购买 nike

Vaadin 8 Grid 中有没有办法自动将所有 JavaBean 模式属性显示为表中的列?并自动用属性名称标记每个列标题?

this page in the Vaadin guide绑定(bind)到数据部分,我们看到这段代码,我们必须明确指定哪些属性用作网格中的列。

Grid<Person> grid = new Grid<>();
grid.setItems(people);
grid.addColumn(Person::getName).setCaption("Name");
grid.addColumn(Person::getBirthYear).setCaption("Year of birth");

最佳答案

是的,这可以通过将 bean 类型作为参数传递给网格构造函数来实现:

Grid<Person> grid = new Grid<>(Person.class);
<小时/>

JavaDoc:

/**
* Creates a new grid that uses reflection based on the provided bean type
* to automatically set up an initial set of columns. All columns will be
* configured using the same {@link Object#toString()} renderer that is used
* by {@link #addColumn(ValueProvider)}.
*
* @param beanType
* the bean type to use, not <code>null</code>
* @see #Grid()
* @see #withPropertySet(PropertySet)
*/

关于java - 默认情况下将我的 JavaBean 的所有属性添加为 Vaadin 8 网格中的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43748576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com