SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
来源:互联网 发布:域名是世界性的吗 编辑:程序博客网 时间:2024/06/05 07:00
转载请注明出处:http://blog.csdn.net/cl61917380/article/details/6265620
培训终于到了最后一个阶段了!
使用工具MyEclipse8.6
今天初探Hibernate老师提前说了SSH的整合,鸡动人心!
过程:
- 版本:struts2.2.1 + spring3.0 + hibernate3.3
- MyEclipse8.6引入JAR包
- 1.引入JAR包:
- a)可以使用myeclipse自带的功能引入所需要的包:
- 右键工程-->MyEclipse--> add Hibernate capabilities,add spring capabilities
- b)struts2的包可以从 下载的目录下复制有 七 个包
- 例如:E:/CL/API/struts-2.2.1.1-all/struts-2.2.1.1/apps/struts2-blank/WEB-INF/lib
- c)还需要插件包 struts2-spring-plugin-2.2.1.1.jar
- 例如:E:/CL/API/struts-2.2.1.1-all/struts-2.2.1.1/lib
- 2.配置文件:(主要是web.xml和applicationContext.xml的配置)
- web.xml:
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- applicationContext.xml:
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
- <!-- 支持元注释 -->
- <context:annotation-config />
- <!-- 扫描包目录 -->
- <context:component-scan base-package="com"></context:component-scan>
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation" value="classpath:hibernate.cfg.xml">
- </property>
- </bean>
- <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- </property>
- </bean>
- </beans>
- hibernate.cfg.xml:
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="dialect">
- org.hibernate.dialect.Oracle9Dialect
- </property>
- <property name="connection.url">
- jdbc:oracle:thin:@localhost:1521:oracle
- </property>
- <property name="connection.username">chenl</property>
- <property name="connection.password">chenl</property>
- <property name="connection.driver_class">
- oracle.jdbc.driver.OracleDriver
- </property>
- <!--
- <mapping resource="com/po/TUser.hbm.xml" />
- <mapping resource="com/po/TDetail.hbm.xml" />
- -->
- </session-factory>
- </hibernate-configuration>
- struts.xml:
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <constant name="struts.enable.DynamicMethodInvocation" value="false" />
- <constant name="struts.devMode" value="true" />
- <package name="user" extends="struts-default" namespace="/user">
- <action name="user" class="com.jungle.action.UserAction">
- </action>
- </package>
- </struts>
图片步骤:
引入spring的包
引入hibernate的包:
一直下一步。。。
- 结束.
- PS:
- 使用hibernateTemplate:
- Action中代码:
- @Component("userAction")
- @Scope("prototype")
- public class UserAction {
- @Resource
- private HibernateTemplate hibernateTemplate;
- public void execute() {
- TUser user = new TUser();
- user.setUsername("aaa");
- TDetail tdetail = new TDetail();
- tdetail.setIdcard("11111111111");
- tdetail.setEmail("aa@qq.com");
- tdetail.setTuser(user);
- user.setTdetail(tdetail);
- hibernateTemplate.save(user);
- hibernateTemplate.flush();
- }
- }
注意: 由于是比较新的版本 所以 整合后需要用到asm3.3版本的jar包而不是asm.jar
下载地址 自己百度(asm3.3.jar)
我把JAR包上传到CSDN了:http://download.csdn.net/detail/cl61917380/5290305
是需要1分的下载积分的^_^
- SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
- SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
- SSH(Spring3.0 + Struts2.1 + Hibernate3.3)整合示例
- 整合Struts2.1+Hibernate3.3+Spring3.0
- ssh最新整合配置(struts2.2.1+ hibernate3.6+spring3.0.5)
- ssh整合配置(struts2.2.1+ hibernate3.6+spring3.0.5)
- ssh整合配置(struts2.2.1+ hibernate3.6+spring3.0.5)
- 【Struts2+Spring3+Hibernate3】SSH框架整合实现CRUD_1.0
- 【Struts2+Spring3+Hibernate3】SSH框架整合实现CRUD_1.3
- SSH快速整合 struts2、Spring3、Hibernate3
- SSH 整合例子 Struts2 Spring3 Hibernate3
- 【Struts2+Spring3+Hibernate3】SSH框架整合
- SSH整合例子 Struts2 Spring3 Hibernate3 注解
- SSH在MyEclipse 8.5下整合详细步骤 (Struts2.1+Spring3.0+Hibernate3.3)
- struts2 spring3 hibernate3整合
- Struts2+Spring3+Hibernate3整合
- Struts2+Hibernate3+Spring3 整合
- Struts2+Spring3+Hibernate3整合
- GCC/LD编译链接潜规则 (第五弹) : 为什么会有undified symbol?
- 二叉查找树的各种操作源码
- android4.2.2 飞思卡尔 编译错误笔记 ubuntu12.04
- U盘安装CentOS6.4
- 左侧是表头的JS表格控件
- SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
- JAVA版文件MD5生成器
- PHP最佳实践
- java class loader mechanism
- Unable to load configuration. - action异常
- c++虚函数的实现机制
- ping功能的实现原理
- java java.lang.Long详解之三 大显神通的位移运算
- LC振荡电路物理分析