TA的每日心情 | 衰 2021-2-2 11:21 |
|---|
签到天数: 36 天 [LV.5]常住居民I
|
/**/ R5 v0 x6 l, i! W Y3 }0 _$ H) p
* 三大框架整合,版本都是最新的
) U5 J4 j, M/ o" |1 J * spring 4.0.5 struts2.3.16.3 hibernate 4.3.5+ D9 G+ O6 \8 T) V- K/ h
*数据库是mysql,JDK是1.6,Tomcat 7.0" ~" L& L. x* f) h: h: U- A9 o
*使用了Hibernate注解,自动创建数据库和表,数据库是hehe,用户名和密码请自己修改! R5 b! {$ Y/ j+ W: \) c7 Z" V
*时间:2014-5-27
- V- p, T* v: s3 r) ~5 Y, e *作者:男孩的天职 O( _. ~/ ], S, }# c5 i0 p0 M
*
* E3 S5 @' l7 P5 Z) n* i6 P */% o m% [ O; T8 C
测试 spring:; l' t/ _0 ^5 S: W. _: Y
- /**% z) t j4 c$ z, D4 d
- * 测试Spring是否整合成功
# R* c! n3 Z' j6 Y& y: U# I$ l3 u5 } - * 同时要开启事务和提交事务1 F0 l$ y) X) w) z. r: {0 Z
- * 整合之后的,不用开启,因为事务已经交给Spring了,所以可以注释掉开启事务和提交事务4 l5 o+ @$ `1 W1 x$ O
- */
. `1 s& l& e0 o$ s3 R$ E+ a - public static void main(String[] args) {
) i2 s7 |9 C' F2 V3 {% l- y - 2 R. g8 m+ O" X( l) P2 y
- ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
1 U' Q0 h: r5 J, J+ p. a - YhxxDao yhxxDao=(YhxxDao) applicationContext.getBean("yhxxDao");
" y4 Q* @1 x5 }, P* W* t/ B0 y - Yhxx yhxx=new Yhxx();% I+ F! R) N3 b' l" K+ b0 J& @
- yhxx.setId(2);//id=2要存在- _4 B& w8 |- D7 n0 G
- yhxxDao.deleteYhxx(yhxx); J# L1 g. N p) {$ ?
- }
复制代码 测试hibernate:& F2 K0 q6 Q0 O0 W- U8 J
- /**
* b" j9 k* W, j4 t0 s& C - * 测试Hiberante是否于数据库连接成功
" A0 C U" `: h - *
! A& V( U; n7 r: F! a# C" Y; } - */
( s# {5 v+ R/ r5 L0 `9 j - public static void main(String[] args) {6 i7 H- O/ V( z5 {7 j3 o3 T* ]
- 1 N- P+ w1 a) F, |
- % u" T2 Q+ n5 R. s! ~
- Session session= HibernateUtil.getSession();- L- z: M5 i4 M7 F4 c2 f
- System.out.println(session);
4 ] _2 e+ N0 I7 Z' c/ {# k7 \
. {5 L! K$ g+ d3 l- }
复制代码 ) J% w4 z- x7 w; k& S
整合资源下载:点击下载
; f; S2 Z8 j: G# W
' ?: Z& F0 E& F; W; F4 ^1 L
7 }+ r; e; I- R! T5 ~! }
- G+ N- `- v3 U4 ~ |
|