On the way learning spring 6

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","[email protected]","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","[email protected]","Cash of software"));
offers1.add(new Offer("sergio","[email protected]","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,任意一个失败,两个都不执行。

时间: 2024-10-01 03:00:13

On the way learning spring 6的相关文章

On the way learning spring 2

Spring 10 - Bean scope Prototype; Request ;Session; Singleton. Source Code: Person person1 = (Person) context.getBean("person"); Person person2 = (Person) context.getBean("person"); person1.setTaxId(666); System.out.println(person2); R

On the way learning spring 3

Spring-12 Factory Beans and Methods static method in Class person non-static method in personFactory Spring-13 The P Namespace 注意Constructor 中的Arg 和建立的Bean之间的关系 p: tag 和 property tag 不要同时使用 Spring-14 Setting List Property In beans.xml file Insert con

On the way learning spring 4

Spring-19 Auto-Wiring  by type 在Xml文件中定义bean之间的关系时,有3种方法: 1. inner bean 2. 在bean 的property中定义另外一个bean 3. Spring Autowiring(有很多种类型, 这里 by type) <bean id="logger" class="com.caveofprogramming.spring.test.Logger" autowire="byType&

On the way learning spring 5

Spring-24 Adding Support for Annotation-Based Wiring Namespace-->check 'context'-->In 'context' Insert <context:annotation-config> element <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.spring

learning spring for Init Project (一)

reference:https://spring.io/quickstart 内容概要: 1 .初始化工程: 首先打开Idea软件, File->New->Project,如下图所示: 选中上图Spring Assistant,这是一个插件用来初始化spring工程.点击上图下一步,如下图所示: 点击Next.如下图所示: 选中上图的Web->Spring Web,然后点击Next,如下图所示: 输入项目名称,选项工程存放路径,点击Next. 如下图所示: 等待工程自动下载相关的jar包

【深度学习Deep Learning】资料大全

转载:http://www.cnblogs.com/charlotte77/p/5485438.html 最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books Deep Learning66 by Yoshua Bengio, Ian Goodfellow and Aaron Courville Neural Networks and Deep Learning42 by Michael Nielsen Deep Learning27 by

【转】The most comprehensive Data Science learning plan for 2017

I joined Analytics Vidhya as an intern last summer. I had no clue what was in store for me. I had been following the blog for some time and liked the community, but did not know what to expect as an intern. The initial few days were good – all the in

DEEP LEARNING 大满贯课程表

Reinforcement Learning post by ISH GIRWAN Courses/Tutorials Deep Reinforcement Learning, Spring 2017, by UC Berkeley: http://rll.berkeley.edu/deeprlcours... Reinforcement Learning, 2015, by UCL (David Siver): http://www0.cs.ucl.ac.uk/staff/d.si... ht

Spring的配置分别是xml和java style

# Spring-IoCSpring配置有两种方式xml和java style ## Spring · spring的IoC(控制反转)就是一个工厂模式变种,<br/> · spring核心就是IoC容器,实现这个容器的接口BeanFactory,BeanFactory是最核心的.最纯粹的<br/> 方法: <br/> getBean() <br/> 实现类: <br/> ApplicationContext <br/> · 简单工厂