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