0
我打算創建desktop application
。在我的應用程序中,服務器和客戶端上的數據庫只是請求服務器獲取數據並返回相應類的對象。如何將數據感知到JavaFX的TableView中
public void serveStudentList() {
BufferedOutputStream bos = null;
ObjectOutputStream oos = null;
Session sess = null;
Transaction tx = null;
try {
bos = new BufferedOutputStream(con.getOutputStream());
oos = new ObjectOutputStream(bos);
sess = HUtil.getSessionFactory().openSession();
tx = sess.beginTransaction();
sess = HUtil.getSessionFactory().openSession();
@SuppressWarnings("unchecked")
List<Student> students = sess.createQuery("FROM Student").list();
tx.commit();
System.out.println("DATABASE query complete.\nWriting Object of List type to the Sream.");
oos.writeObject(students);
oos.flush();
System.out.println("Object Wrote...\n Closing this stream now.");
oos.close();
bos.close();
con.close();
} catch (IOException e) {
e.printStackTrace();
} catch (HibernateException he) {
if (tx != null) {
tx.rollback();
}
he.printStackTrace();
} finally {
sess.close();
}
現在我想用這個學生對象來填充TableView
。
我想填充數據到TableView使用簡單的字符串對象,我不能這樣做?我不想使用SimpleStringPropery
,我想使用String
對象。 我使用休眠,所以我映射我所有的類
列表學生= sess.createQuery(「FROM Student」)。list();現在我想用這個對象來感受TableView。那麼我該如何做到這一點。 –
創建'ObservalbleList'而不是'List '。更新我的答案! –
ItachiUchiha
您當然可以在表列而不是StringProperties中使用字符串。假設您的Student類具有其屬性的getXXX()方法,只需使用PropertyValueFactory作爲TableColumns上的CellValueFactory即可。但是,如果您希望表格是可編輯的,那麼您將需要做一些額外的工作。 –