首页 > 编程语言 > 详细

On the way learning spring 6

时间:2015-10-30 01:56:44      阅读:287      评论:0      收藏:0      [点我收藏+]

Spring-47 Adding an Update Method to the DAO

public boolean update(Offer offer){
BeanPropertySqlParameterSource params
= new BeanPropertySqlParameterSource(offer); return jdbc.update("update offers set name=:name,text=:text,email=:email where id =:id",params) == 1;
}
Offer offer = new Offer(2,"nfd","nfd@gmail.com","iwtkurf");
        if(offersDao.update(offer)){
            System.out.println("Object update");
        }else{
            System.out.println("Cannot update object");
        }

 

Spring-48 Batch Updates:Prepared Statements

    public int[] create(List<Offer> offers){
     SqlParameterSource[] params = SqlParameterSourceUtils.createBatch(offers.toArray());
        return jdbc.batchUpdate("insert into offers(name,text,email) values (:name, :text, :email)", params);
    }
List<Offer> offers1=new ArrayList<Offer>();
offers1.add(new Offer("Dave","dave@caveofprogramming","Cash of software"));
offers1.add(new Offer("sergio","sergio@caveofprogramming","Cash of hardware");
            
int[] rvals = offersDao.create(offers1);
for(int value: rvals){
     System.out.println("Updated"+ value+" rows.");
}

 

Spring-49 Transactions

Add bean "DataSourceTransactionManager"--->set ref "dataSource"

check "tx" in Namespace

In "tx" ----->insert "tx:annotationdriven element"

 

标记为@Transactional时,两个sql,任意一个失败,两个都不执行。

 

On the way learning spring 6

原文:http://www.cnblogs.com/patrickspring/p/4922222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!