Spring saveorupdateall method: saves or updates the collection of entity objects

saveOrUpdateAll(Collection entities)@H_ 403_ 3 @ Parameter Description:

Example 1

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);  //执行保存操作
}

Example 2

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);  //执行修改操作
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>