0
我试图在简单的vaadin UI中从我的数据库打印值。我是从这个教程做的一切:https://vaadin.com/blog/-/blogs/building-a-web-ui-for-mysql-databases-in-plain-java-java.lang.IllegalArgumentException:无法解析属性设置bean的属性名hourtoreserve com.ti.project.vaadin.vaadinprojectti.Day
我改变了一点,我想不通为什么我不能用自己的一组列。如果我评论与setColumns和bindInstanceFields一切正常,但在相反的顺序线......在另一种情况下,我得到的标题提到的错误。
下面的代码:
日类别:
package com.ti.project.vaadin.vaadinprojectti;
public class Day {
private String hourToReserve;
private String reservedOn;
public Day(String hourToReserve, String reservedOn) {
this.hourToReserve = hourToReserve;
this.reservedOn = reservedOn;
}
public String getHourToReserve() {
return hourToReserve;
}
public void setHourToReserve(String hourToReserve) {
this.hourToReserve = hourToReserve;
}
public String getReservedOn() {
return reservedOn;
}
public void setReservedOn(String reservedOn) {
this.reservedOn = reservedOn;
}
}
DayService类别:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class DayService {
@Autowired
private JdbcTemplate jdbcTemplate;
public List<Day> findAll(String dayName) {
return jdbcTemplate.query(
"SELECT hourtoreserve, reservedon FROM " + dayName,
(rs, rowNum) -> new Day(
rs.getString("hourtoreserve"),
rs.getString("reservedon")));
}
public void update(Day day, String dayName){
jdbcTemplate.update(
"UPDATE " + dayName + " SET reservedon=?",
day.getReservedOn());
}
}
和Vaadin UI代码,其中发生了错误:
package com.ti.project.vaadin.vaadinprojectti;
import com.vaadin.data.Binder;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.*;
import org.springframework.beans.factory.annotation.Autowired;
@SpringUI
public class VaadinUI extends UI {
@Autowired
private DayService service;
private Day day;
private Binder<Day> binder = new Binder<>(Day.class);
private Grid<Day> grid = new Grid(Day.class);
@Override
protected void init(VaadinRequest request) {
updateGrid();
grid.setColumns("hourtoreserve", "reservedon"); // if this is commented
binder.bindInstanceFields(this); // it works but columns are in wrong order
VerticalLayout layout = new VerticalLayout(grid);
setContent(layout);
}
private void updateGrid() {
List<Day> days = service.findAll("monday");
grid.setItems(days);
}
的确不同,Vaadin使用反射来检查你的秘密,所以它会找到_houeToReserve_财产,而不是_hourtoreserve_。 – Morfic