ssh注解版

SSH不是一个框架,而是多个框架(struts+spring+hibernate)的集成,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活、易于扩展的多层Web应用程序

Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持。Spring一方面作为一个轻量级的IoC容器,负责查找、定位、创建和管理对象及对象之间的依赖关系,另一方面能使Struts和Hibernate更好地工作。

在搭建框架之前导入相应的jar包

struts2相关的jar包:

commons-io-2.0.1.jar     commons项目(commons项目就是java中一些常用的公共的组件)的io子项目,是处理异常的

commons-fileupload-1.2.2.jar           commons项目中的关于文件上传的包, struts2.1.6版本后必须加入此文件

commons-lang3-3.1.jar       commons项目中的lang包

freemarker-2.3.19.jar             支持freemarker(struts2的UI标签的模板使用FreeMarker编写)的,在webwork中也有

javassist-3.11.0.GA.jar        一个开源的分析、编辑和创建Java字节码的类库(hibernate中也需要,引入其中一个即可)

ognl-3.0.5.jar                支持ognl语言(对象图导航语言(Object Graph Navigation  Language))的,struts2框架通过其读写对象的属                   性,webwork也支持ognl语言

struts2-core-2.3.4.1.jar        struts2的核心jar包

xwork-core-2.3.4.1.jar        xwork的核心jar包,由于struts2是webwork的升级版本,所以必定对其有所依赖(struts2在其基础上                  构建)


hibernate相关的jar包:

antlr-2.7.6.jar

commons-collections-3.1.jar               commons项目中的子项目,是对collection集合的封装

dom4j-1.6.1.jar                                              对dom4j的封装,是解析xml文件的

hibernate-jpa-2.0-api-1.0.0.Final.jar      对JPA(Java持久化API)规范的支持

hibernate3.jar                                     hibernate的核心jar包                 

jta-1.1.jar                                            hibernate对事务的处理

slf4j-api-1.6.1.jar                               一个日志系统的服务的api,SLF4J是一个用于日志系统的简单Facade,允许最终用户在部署其应用时使用                        其所希望的日志系统


spring-aop相关的jar包:

aopalliance.jar

aspectjrt.jar

aspectjweaver.jar

spring-aop-3.2.5.RELEASE.jar


spring-core相关的jar包:

commons-logging-1.1.3.jar

spring-beans-3.2.5.RELEASE.jar

spring-context-3.2.5.RELEASE.jar

spring-core-3.2.5.RELEASE.jar

spring-expression-3.2.5.RELEASE.jar


spring-orm相关的jar包:

c3p0-0.9.2-pre1.jar

mchange-commons-java-0.2.3.4.jar

mysql-connector-java-5.0.8-bin.jar

spring-jdbc-3.2.5.RELEASE.jar

spring-orm-3.2.5.RELEASE.jar

spring-tx-3.2.5.RELEASE.jar


spring-web相关的jar包:

spring-web-3.2.5.RELEASE.jar

struts2-spring-plugin-2.3.4.1.jar


web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <filter>
    <filter-name>OpenSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>OpenSessionInView</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>
  <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:bean.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<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:aop="http://www.springframework.org/schema/aop"
      xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:mvc="http://www.springframework.org/schema/mvc"

      xsi:schemaLocation="

 http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-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
 
 http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        
      ">
      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="user" value="root"></property>
<property name="password" value="mysql"></property>
<property name="initialPoolSize" value="3"></property>
<property name="maxPoolSize" value="10"></property>
<property name="maxStatements" value="100"></property>
<property name="acquireIncrement" value="2"></property>
</bean> 
     <context:component-scan base-package="*"></context:component-scan>


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props >
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>entity.Dept</value>
</list>
</property> 

   
</bean> 



<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>




<tx:annotation-driven transaction-manager="txManager"/>


</beans>
  




   entity实体类


@Entity

@Table(name="dept")

public class Dept {

 @Id

 @GeneratedValue(strategy=GenerationType.IDENTITY)

private Integer id;

 @Column(name="name")

private String name;









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值