我的方法在負(fù)責(zé) Vaadin View 的類中調(diào)用。當(dāng)他們嘗試在主類中調(diào)用它進(jìn)行測(cè)試時(shí),一切正常。這是我在 Repository 類中的方法,我的問題是關(guān)于 findAll 類:@Repositorypublic class SeansRepository { @Autowired JdbcTemplate jdbcTemplate; public Seans findById(long id) { return jdbcTemplate.queryForObject("select * from seans where id=? ", new Object[] { id }, new BeanPropertyRowMapper<Seans>(Seans.class)); } public Collection<Seans> findAll() { Collection<Seans> seans = (Collection<Seans>) jdbcTemplate.query("select * from seans", new BeanPropertyRowMapper(Seans.class)); return seans; } public int deleteById(long id) { return jdbcTemplate.update("delete from seans where id=?", new Object[] { id }); }}這是在 View 類中調(diào)用方法的方式:@DesignRoot@AutoGenerated@SuppressWarnings("serial")public class ChoseNumberOfTicketsView extends AbsoluteLayout implements View{ protected TextField nameTextField; protected TextField surnameTextField; protected Label menuLabel; protected TextField emailTextField; protected TextField dticketsTextField; protected TextField nticketsTextField; protected ComboBox<Seans> movieComboBox; private SeansRepository repository; public ChoseNumberOfTicketsView() { Design.read(this); repository = new SeansRepository(); movieComboBox = new ComboBox<>("Chose the movie"); movieComboBox.setItems(repository.findAll()); }}我正在嘗試獲取電影列表并將其放在 ComboBox 中以供選擇。我正在添加一個(gè) UI 類,其中包含我的視圖實(shí)例:@SpringUIpublic class KinoUI extends UI{ Navigator navigator; @Override protected void init(VaadinRequest request) { getPage().setTitle("Exam"); navigator = new Navigator(this, this); navigator.addView("", new StartView()); navigator.addView("chosenumberoftickets", new ChoseNumberOfTicketsView()); }}
1 回答

PIPIONE
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
感謝您添加查看代碼。
問題是您SeansRepository使用new關(guān)鍵字創(chuàng)建自己。這樣做,它不會(huì)由 Spring 管理,因此 Spring 不會(huì)自動(dòng)裝配您的JdbcTemplate.
SeansRepository相反,你也需要自動(dòng)裝配你的,試試這個(gè)
@Autowired
public ChoseNumberOfTicketsView(SeansRepository repository) {
Design.read(this);
this.repository = repository;
movieComboBox = new ComboBox<>("Chose the movie");
movieComboBox.setItems(repository.findAll());
}
添加回答
舉報(bào)
0/150
提交
取消