雜家
學(xué)習(xí)復(fù)習(xí)
|
首頁
|
發(fā)新隨筆
|
發(fā)新文章
|
聯(lián)系
|
聚合
|
管理
spring+hibernate代碼的基本內(nèi)容
可以執(zhí)行的最小內(nèi)容
1.pojo-User.java
package
com.xzl.pojo;
import
java.util.Date;
/** */
/**
* @hibernate.class table="jordan"
*/
public
class
User
{
public
Integer id;
public
String name;
public
Integer age;
public
Date birth;
public
String comment;
/** */
/**
* @hibernate.
*/
public
Integer getAge()
{
return
age;
}
/** */
/**
*
@param
age the age to set
*/
public
void
setAge(Integer age)
{
this
.age
=
age;
}
/** */
/**
*
@return
the birth
*/
public
Date getBirth()
{
return
birth;
}
/** */
/**
*
@param
birth the birth to set
*/
public
void
setBirth(Date birth)
{
this
.birth
=
birth;
}
/** */
/**
*
@return
the comment
*/
public
String getComment()
{
return
comment;
}
/** */
/**
*
@param
comment the comment to set
*/
public
void
setComment(String comment)
{
this
.comment
=
comment;
}
/** */
/**
*
@return
the id
*/
public
Integer getId()
{
return
id;
}
/** */
/**
*
@param
id the id to set
*/
public
void
setId(Integer id)
{
this
.id
=
id;
}
/** */
/**
*
@return
the name
*/
public
String getName()
{
return
name;
}
/** */
/**
*
@param
name the name to set
*/
public
void
setName(String name)
{
this
.name
=
name;
}
}
2.映射文件User.hbm.xml
<?
xml version="1.0"
?>
<!
DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
>
<
hibernate-mapping
>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<
class
name
="com.xzl.pojo.User"
table
="jordan"
>
<
meta
attribute
="class-description"
inherit
="false"
>
@hibernate.class
table="jordan"
</
meta
>
<
id
name
="id"
type
="java.lang.Integer"
column
="id"
>
<
meta
attribute
="field-description"
>
@hibernate.id
generator-class="assigned"
type="java.lang.Object"
column="id"
</
meta
>
<
generator
class
="native"
/>
</
id
>
<
property
name
="name"
type
="java.lang.String"
column
="name"
not-null
="true"
length
="10"
>
<
meta
attribute
="field-description"
>
@hibernate.property
column="name"
length="10"
not-null="true"
</
meta
>
</
property
>
<
property
name
="age"
type
="java.lang.Integer"
column
="age"
not-null
="true"
length
="10"
>
<
meta
attribute
="field-description"
>
@hibernate.property
column="age"
length="10"
not-null="true"
</
meta
>
</
property
>
<
property
name
="birth"
type
="java.sql.Timestamp"
column
="birth"
not-null
="true"
length
="19"
>
<
meta
attribute
="field-description"
>
@hibernate.property
column="birth"
length="19"
not-null="true"
</
meta
>
</
property
>
<
property
name
="comment"
type
="java.lang.String"
column
="comment"
not-null
="true"
length
="100"
>
<
meta
attribute
="field-description"
>
@hibernate.property
column="comment"
length="100"
not-null="true"
</
meta
>
</
property
>
<!--
Associations
-->
</
class
>
</
hibernate-mapping
>
3.DAO接口IUserDAO.java
package
com.xzl.star;
import
com.xzl.pojo.User;
public
interface
IUserDAO
{
public
User doQuery(java.lang.Integer id);
}
4.實(shí)現(xiàn)UserDAO繼承HibernateDaoSupport類,調(diào)用模板getHibernateTemplate
package
com.xzl.star;
import
org.apache.log4j.Logger;
import
org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import
com.xzl.pojo.User;
public
class
UserDAO
extends
HibernateDaoSupport
implements
IUserDAO
{
private
Logger logger
=
Logger.getLogger(
this
.getClass().getName());
public
User doQuery( java.lang.Integer id)
{
//
TODO Auto-generated method stub
logger.info(
"
進(jìn)入doQuery方法
"
);
try
{
return
(User)getHibernateTemplate().get(User.
class
,id);
}
catch
(Exception e)
{
logger.info(
"
拋出異常
"
+
e.getMessage());
}
finally
{
logger.info(
"
doQuery方法完成
"
);
}
return
null
;
}
}
5.測試
package
com.xzl.star;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.FileSystemXmlApplicationContext;
import
org.hibernate.dialect.MySQL5Dialect;
public
class
TestMain
{
/** */
/**
*
@param
args
*/
public
static
void
main(String[] args)
{
//
TODO Auto-generated method stub
ApplicationContext ctx
=
new
FileSystemXmlApplicationContext(
"
src/hibernate-Context.xml
"
);
IUserDAO userDao
=
(IUserDAO)ctx.getBean(
"
userDAOProxy
"
);
System.out.println(userDao.doQuery(
1
).getName());
System.out.println(userDao.doQuery(
3
));
}
}
6.hibernate-Context.xml配置所有。。。
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"
>
<
beans
>
<
bean
id
="dataSource"
class
="org.apache.commons.dbcp.BasicDataSource"
destroy-method
="close"
>
<
property
name
="driverClassName"
>
<
value
>
org.gjt.mm.mysql.Driver
</
value
>
</
property
>
<
property
name
="url"
>
<
value
>
jdbc:mysql://localhost:3306/SPORT
</
value
>
</
property
>
<
property
name
="username"
>
<
value
>
root
</
value
>
</
property
>
<
property
name
="password"
>
<
value
></
value
>
</
property
>
</
bean
>
<
bean
id
="sessionFactory"
class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<
property
name
="dataSource"
>
<
ref
local
="dataSource"
/>
</
property
>
<
property
name
="mappingResources"
>
<
list
>
<
value
>
com/xzl/pojo/User.hbm.xml
</
value
>
</
list
>
</
property
>
<
property
name
="hibernateProperties"
>
<
props
>
<
prop
key
="hibernate.dialect"
>
org.hibernate.dialect.MySQL5Dialect
</
prop
>
<
prop
key
="hibernate.show_sql"
>
true
</
prop
>
</
props
>
</
property
>
</
bean
>
<
bean
id
="transactionManager"
class
="org.springframework.orm.hibernate3.HibernateTransactionManager"
>
<
property
name
="sessionFactory"
>
<
ref
local
="sessionFactory"
/>
</
property
>
</
bean
>
<
bean
id
="userDAO"
class
="com.xzl.star.UserDAO"
>
<
property
name
="sessionFactory"
>
<
ref
local
="sessionFactory"
/>
</
property
>
</
bean
>
<
bean
id
="userDAOProxy"
class
="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
>
<
property
name
="transactionManager"
>
<
ref
bean
="transactionManager"
/>
</
property
>
<
property
name
="target"
>
<
ref
local
="userDAO"
/>
</
property
>
<
property
name
="transactionAttributes"
>
<
props
>
<
prop
key
="do*"
>
PROPAGATION_REQUIRED,readOnly
</
prop
>
</
props
>
</
property
>
</
bean
>
</
beans
>
就結(jié)束了,自己留著用的!
ExtJS教程
-
Hibernate教程
-
Struts2 教程
-
Lucene教程
發(fā)表于 2007-04-19 22:25
淘聲依舊
閱讀(623)
評(píng)論(0)
編輯
收藏
所屬分類:
109.Spring
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
解決通過POST頁面提交后,顯示亂碼問題!
一種優(yōu)雅的流行架構(gòu):Struts+Spring+Hibernate
spring+hibernate代碼的基本內(nèi)容
Spring Quartz任務(wù)調(diào)度示例
web.xml樣板2.4的
*-servlet的Spring MVC樣板
Spring - PropertyPlaceholder
Spring MVC
Spring JavaMail的示例
<
2007年4月
>
日
一
二
三
四
五
六
25
26
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
1
2
3
4
5
公告
要冒一險(xiǎn)!整個(gè)生命就是一場冒險(xiǎn),走得最遠(yuǎn)的人常是愿意去做、愿意去冒險(xiǎn)的人。
隨筆分類
(153)
100.Struts2(27)
(rss)
101.Compass
(rss)
102.ExtJS(23)
(rss)
103.Hibernate(25)
(rss)
104.Java(30)
(rss)
105.JavaScript(22)
(rss)
106.jBPM(1)
(rss)
107.Log4j(1)
(rss)
108.Lucene(13)
(rss)
109.Spring(9)
(rss)
110.Things(2)
(rss)
實(shí)用連接
天堂露珠
我的心情
西安信息資源網(wǎng)
積分與排名
積分 - 96713
排名 - 595
最新評(píng)論
1.?re: JSTL fmt:formatNumber 數(shù)字、貨幣格式化
非發(fā)放
--非發(fā)放
2.?re: JSTL fmt:formatNumber 數(shù)字、貨幣格式化
<fmt:formatNumber value="60000" pattern="#,#00#"/>
--非發(fā)放
3.?re: java圖片處理 (文字水印、圖片水印、縮放、補(bǔ)白)
好東西!
謝謝!
--rb
4.?re: JQuery1.2API中文文檔[未登錄]
hao
--123
5.?re: Java獲取各種常用時(shí)間方法
很好很強(qiáng)大
--`萬物皆對(duì)象`
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 淘聲依舊
hits
Casino
主站蜘蛛池模板:
亚洲成人福利在线
|
国产成人精品日本亚洲专一区
|
亚洲精品在线不卡
|
亚洲第一综合天堂另类专
|
久久免费香蕉视频
|
在线v片免费观看视频
|
国产啪亚洲国产精品无码
|
亚洲熟妇av一区二区三区漫画
|
亚洲永久中文字幕在线
|
一本岛v免费不卡一二三区
|
一本岛高清v不卡免费一三区
|
国产国拍亚洲精品福利
|
我们的2018在线观看免费高清
|
亚洲国产成人久久一区WWW
|
亚洲首页在线观看
|
免费一级特黄特色大片
|
久久国内免费视频
|
亚洲伊人久久大香线蕉综合图片
|
国产亚洲福利在线视频
|
免费高清国产视频
|
jjzz亚洲亚洲女人
|
亚洲激情视频图片
|
久久久久久久99精品免费
|
一本色道久久88亚洲综合
|
亚洲中文无码a∨在线观看
|
中文字幕免费在线看电影大全
|
亚洲三级视频在线
|
a级成人毛片免费视频高清
|
免费A级毛片无码A
|
国产精品亚洲片在线va
|
无码国产精品一区二区免费3p
|
免费无码一区二区
|
免费观看的毛片手机视频
|
亚洲视频欧洲视频
|
中文字幕免费播放
|
亚洲高清无码在线观看
|
亚洲精品伦理熟女国产一区二区
|
亚洲精品视频在线观看免费
|
亚洲成AV人片在线观看WWW
|
人人公开免费超级碰碰碰视频
|
免费看又爽又黄禁片视频1000
|