TA的每日心情 | 衰 2021-2-2 11:21 |
|---|
签到天数: 36 天 [LV.5]常住居民I
|
/**
0 t+ F$ d: E) z * 三大框架整合,版本都是最新的
4 y9 d# r; B7 s' Z& c7 S/ r- M * spring 4.0.5 struts2.3.16.3 hibernate 4.3.5
& }6 e9 ?* U" e/ j *数据库是mysql,JDK是1.6,Tomcat 7.0
$ h- E. u8 l4 I' N *使用了Hibernate注解,自动创建数据库和表,数据库是hehe,用户名和密码请自己修改
3 d5 _5 c1 M+ P. `) F *时间:2014-5-27; ~: E# i }( {4 M) }1 R I
*作者:男孩的天职
, _( ?% \+ e3 @/ w+ n& Y% _/ g *
) K% r k7 C; s1 ^& t */
5 k' E+ A# E3 u8 R: v测试 spring:
& g$ ^; N/ ~$ x+ ^ R: p* C* c2 P0 y- /**
% l) j$ V- ~6 X ]6 w - * 测试Spring是否整合成功
+ a- e4 g" T5 b, | - * 同时要开启事务和提交事务
7 l8 {# g8 j$ Z* s- _3 e - * 整合之后的,不用开启,因为事务已经交给Spring了,所以可以注释掉开启事务和提交事务6 }( S, _/ J7 @' \: m1 I
- */, C3 U; ?% c* N* b0 Y+ f8 q( i" d
- public static void main(String[] args) {2 R& Z" i: M! v- Q; h
-
; }+ L6 r8 U1 d0 o+ S - ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
6 s/ n7 t, H; f4 g z6 ` - YhxxDao yhxxDao=(YhxxDao) applicationContext.getBean("yhxxDao");
# k" P. J) x" L - Yhxx yhxx=new Yhxx();* t, }" N: s! c
- yhxx.setId(2);//id=2要存在! F, i' F0 P b4 ^; F, [
- yhxxDao.deleteYhxx(yhxx);* F4 ~" o. w, u+ @9 F9 q
- }
复制代码 测试hibernate:2 p( Q/ ?, H8 w7 a$ P( c
- /**
" C. [7 f: v# N% w8 [/ m - * 测试Hiberante是否于数据库连接成功
6 z3 O4 K" {5 B; f - *% u7 o6 R9 A2 i- b
- */
& x; t- c/ k! a r \. W1 W3 i - public static void main(String[] args) {
/ |. D- H1 i% a7 u9 r" ? -
; M+ ?; x; j/ T7 g- R - , |8 C# ?( h! N# M5 A
- Session session= HibernateUtil.getSession();
6 i$ s; T& ^+ j9 A+ P$ \ - System.out.println(session);! z' s# ^7 C. \; o l# P
- 1 G) o; P+ s0 D( f6 ~
- }
复制代码 + W; h4 b) n$ x
整合资源下载:点击下载
6 D3 {5 |+ U8 h" J' \$ ?% S! o. {: e1 k) v) U- L( [& ~
( n: s, _ n* S; a( |, s8 l+ C! H7 W0 n# \* g
|
|