saveOrUpdateAll(Collection entities)
引數說明:public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //載入組態檔 Dao dao = (Dao)context.getBean("dao"); //建立Dao HibernateTemplate htm = dao.getHibernateTemplate(); TbUser user1 = new TbUser("使用者1","男",27); //新增資料 TbUser user2 = new TbUser("使用者2","男",27); TbUser user3 = new TbUser("使用者3","男",27); List list = new ArrayList(); list.add(user1); list.add(user2); list.add(user3); htm.saveOrUpdateAll(list); //執行儲存操作 }
public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //載入組態檔 Dao dao = (Dao)context.getBean("dao"); //建立Dao HibernateTemplate htm = dao.getHibernateTemplate(); List list = htm.loadAll(TbUser.class); //……省略修改集合中的實體物件的程式碼 htm.saveOrUpdateAll(list); //執行修改操作 }