spring开发_spring+hibernate(三)

2014-11-24 07:28:34 · 作者: · 浏览: 1
1 for (Person person : list) {
52 System.out.println(person.getId() + " " + person.getName() + " "
53 + person.getAge() + " " + person.getSex());
54 }
55 }
56
57 @Test
58 public void testDelete() {
59 personService.delete(1);
60 }
61
62 }

/spring+hibernate/src/bean.xml
1 < xml version="1.0" encoding="UTF-8" >
2 http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans
6 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
8 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
10
11
12
13
14
15
16 17 destroy-method="close">
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32 33 class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
34
35
36
37
38
39
40
41 com/b510/domain/Person.hbm.xml
42

43

44
45
46
47
48 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
49 hibernate.hbm2ddl.auto=update
50 hibernate.show_sql=true
51 hibernate.format_sql=true
52 hibernate.cache.use_second_level_cache=true
53 hibernate.cache.use_query_cache=false
54 hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
55

56

57

58
59
60
61 62 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
63
64

65
66
67
68
69
70


这里我们可以重写占位符配置器:
那么/spring+hibernate/src/bean.xml的另外一种配置方式是:要知道,程序执行是完全相同的。

1 < xml version="1.0" encoding="UTF-8" >
2 http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans
6 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
8 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
10
11
12