最新版Struts2+Hibernate+Spring整合
目前为止三大框架最新版本是:
struts2.3.16.1
hibernate4.3.4
spring4.0.2
其中struts2和hibernate的下载方式比较简单,但是spring下载有点麻烦,可以直接复制下面链接下载最新版spring
http://repo.springsource.org/libs-release-local/org/springframework/spring/4.0.2.RELEASE/spring-framework-4.0.2.RELEASE-dist.zip
一. 所需的jar包(其中aopaliance-1.0.jar,是spring所依赖的jar,直接复制粘贴到谷歌百度就有的下载)
框架
|
版本
|
所需jar包
|
Struts2
|
2.3.16.1
|
 |
Hibernate
|
4.3.4 
|
spring
|
4.0.2
|
二. 创建一张表
-
CREATE TABLE `user` (
-
-
`id` int(11) NOT NULL AUTO_INCREMENT,
-
-
`user_name` varchar(20) DEFAULT NULL,
-
-
`password` varchar(20) DEFAULT NULL,
-
-
`address` varchar(100) DEFAULT NULL,
-
-
`phone_number` varchar(20) DEFAULT NULL,
-
-
`create_time` datetime DEFAULT NULL,
-
-
`update_time` datetime DEFAULT NULL,
-
-
PRIMARY KEY (`id`)
-
-
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULTCHARSET=utf8;
-
-
---并插入一条数据
-
INSERT INTO `user` VALUES ("1', 'test','test', 'test', 'test', '2014-03-29 00:48:14', '2014-03-29 00:48:17');
三. 先看下myeclipse的目录结构


四. 配置文件
1. web.xml
-
<!--?xml version="1.0" encoding="UTF-8"?-->
-
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee
-
http:
-
<display-name></display-name>
-
-
<!-- 添加对spring的支持 -->
-
<context-param>
-
<param-name>contextConfigLocation</param-name>
-
<param-value>classpath:applicationContext.xml</param-value>
-
</context-param>
-
-
<listener>
------分隔线----------------------------
------分隔线----------------------------