亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我嘗試在 Vaadin View 中初始化方法時

當我嘗試在 Vaadin View 中初始化方法時

慕容708150 2023-06-08 19:59:51
我的方法在負責 Vaadin View 的類中調用。當他們嘗試在主類中調用它進行測試時,一切正常。這是我在 Repository 類中的方法,我的問題是關于 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 類中調用方法的方式:@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 中以供選擇。我正在添加一個 UI 類,其中包含我的視圖實例:@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貢獻1829條經驗 獲得超9個贊

感謝您添加查看代碼。


問題是您SeansRepository使用new關鍵字創建自己。這樣做,它不會由 Spring 管理,因此 Spring 不會自動裝配您的JdbcTemplate.


SeansRepository相反,你也需要自動裝配你的,試試這個


@Autowired

public ChoseNumberOfTicketsView(SeansRepository repository) {

    Design.read(this);  

    this.repository = repository;

    movieComboBox = new ComboBox<>("Chose the movie");

    movieComboBox.setItems(repository.findAll());


}


查看完整回答
反對 回復 2023-06-08
  • 1 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號