Java 技术研究 欢迎大家
欢迎大家 来到我的blog , 如果我身边的朋友 有什么不懂可以直接来问我 我会细心的帮助你的. 如果网络上的朋友有什么不懂的 可以加我QQ48187537
posts - 37, comments - 21, trackbacks - 0, articles - 1
导航
BlogJava
首页
新随笔
联系
聚合
管理
<
2008年8月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(2)
给我留言
查看公开留言
查看私人留言
随笔档案
2008年10月 (1)
2008年8月 (1)
2008年7月 (1)
2008年3月 (2)
2008年2月 (4)
2008年1月 (4)
2007年12月 (1)
2007年11月 (3)
2007年10月 (2)
2007年9月 (4)
2007年8月 (14)
文章档案
2007年8月 (1)
搜索
最新评论
1. re: Hibernate 悲观锁 and 乐观锁
很好,在处理并发业务的时候需要根据具体情况作出选择。
--月亮之上
2. hh[未登录]
erer
--h
3. re: Hibernate 悲观锁 and 乐观锁
不错
--jdlsfl
4. re: JSP实现帐号密码登录的一个小项目 做成视频
你真有才 !!~~
--wang lei
5. re: JSP实现帐号密码登录的一个小项目 做成视频
vcxvcxvcx
--xv
阅读排行榜
1. 教大家SQL 内连接(920)
2. 教大家对 String 实例 详细了解 ...(449)
3. Hibernate 悲观锁 and 乐观锁(427)
4. JSF 一些经验(386)
5. 教大家使用IO包的 从键盘输入(256)
评论排行榜
1. 刚做出来的 struts 入门视频 非常适合新人(4)
2. JSP实现帐号密码登录的一个小项目 做成视频(3)
3. 教大家对 String 实例 详细了解 ...(3)
4. 教大家学J2SE 一定要看啊(3)
5. 教大家使用IO包的 从键盘输入(3)
spring 整合hibernate
Posted on 2008-08-14 14:52
郑成桥
阅读(62)
评论(0)
编辑
收藏
首先 顺序导入 spring hibernate struts
配置applicationContet.xml
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<
beans
xmlns
=
"
http://www.springframework.org/schema/beans
"
xmlns:xsi
=
"
http://www.w3.org/2001/XMLSchema-instance
"
xsi:schemaLocation
=
"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
"
>
<
bean id
=
"
datasource
"
class
=
"
com.mchange.v2.c3p0.ComboPooledDataSource
"
destroy
-
method
=
"
close
"
>
<
property name
=
"
driverClass
"
value
=
"
com.microsoft.jdbc.sqlserver.SQLServerDriver
"
>
</
property
>
<
property name
=
"
jdbcUrl
"
value
=
"
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=blog;SelectMethod=cursor
"
>
</
property
>
<
property name
=
"
user
"
value
=
"
sa
"
></
property
>
<
property name
=
"
password
"
value
=
"
sa
"
></
property
>
<
property name
=
"
minPoolSize
"
value
=
"
5
"
></
property
>
<
property name
=
"
maxPoolSize
"
value
=
"
20
"
></
property
>
<
property name
=
"
acquireIncrement
"
value
=
"
5
"
></
property
>
</
bean
>
<
bean id
=
"
sessionFactory
"
class
=
"
org.springframework.orm.hibernate3.LocalSessionFactoryBean
"
>
<
property name
=
"
dataSource
"
>
<
ref bean
=
"
datasource
"
/>
</
property
>
<
property name
=
"
hibernateProperties
"
>
<
props
>
<
prop key
=
"
hibernate.dialect
"
>
org.hibernate.dialect.SQLServerDialect
</
prop
>
<
prop key
=
"
hibernate.show_sql
"
>
true
</
prop
>
</
props
>
</
property
>
<
property name
=
"
mappingDirectoryLocations
"
>
<
list
>
<
value
>
classpath:
/
com
/
zcq
/
dao
</
value
>
</
list
>
</
property
>
</
bean
>
<!--
hibernateTemplate 配置
-->
<
bean id
=
"
hibernateTemplate
"
class
=
"
org.springframework.orm.hibernate3.HibernateTemplate
"
>
<
property name
=
"
sessionFactory
"
>
<
ref bean
=
"
sessionFactory
"
/>
</
property
>
</
bean
>
<!--
zcqbb datable
-->
<
bean id
=
"
daoimp
"
class
=
"
com.zcq.dao.Test
"
>
<
property name
=
"
hibernateTemplate
"
ref
=
"
hibernateTemplate
"
/>
</
bean
>
</
beans
>
然后写接口
然后实现接口
package
com.zcq.job.dao;
import
org.springframework.context.ApplicationContext;
import
org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import
com.zcq.job.I.Zcq_I;
public
class
Zcq_Imp
extends
HibernateDaoSupport
implements
Zcq_I
{
public
void
show()
{
System.out.println(
"
sssssss
"
);
}
public
static
Zcq_I getApplication(ApplicationContext ctx)
{
return
(Zcq_I)ctx.getBean(
"
daoimp
"
);
}
}
web.xml 里加入
<
context
-
param
>
<
param
-
name
>
contextConfigLocation
</
param
-
name
>
<
param
-
value
>/
WEB
-
INF
/
applicationContext.xml
</
param
-
value
>
</
context
-
param
>
<
listener
>
<
listener
-
class
>
org.springframework.web.context.ContextLoaderListener
</
listener
-
class
>
</
listener
>
<
filter
>
<
filter
-
name
>
CharacterEncodingFilter
</
filter
-
name
>
<
filter
-
class
>
org.springframework.web.filter.CharacterEncodingFilter
</
filter
-
class
>
<
init
-
param
>
<
param
-
name
>
encoding
</
param
-
name
>
<
param
-
value
>
gbk
</
param
-
value
>
</
init
-
param
>
<
init
-
param
>
<
param
-
name
>
forceEncoding
</
param
-
name
>
<
param
-
value
>
true
</
param
-
value
>
</
init
-
param
>
</
filter
>
<
filter
-
mapping
>
<
filter
-
name
>
CharacterEncodingFilter
</
filter
-
name
>
<
url
-
pattern
>
/**/
/*
</url-pattern>
</filter-mapping>
IT新闻
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关链接:
网站导航:
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理
Powered by:
BlogJava
Copyright © 郑成桥