ssh整合

第一步:使用Eclipse创建一个动态web项目 注意的是要勾选创建XML文件
在这里插入图片描述
第二步:导入SSH整合的核心jar包
hibernate的jar包如下:
在这里插入图片描述
如下是struct的jar包
在这里插入图片描述
如下是spring的jar包
在这里插入图片描述
把以上jar包导入到所创建的项目中去 ssh所有依赖的jar包导入完成
第三步:
配置web.xml文件
配置web.xml文件的核心过滤器

struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter


struts2
/*

创建hibernate.cfg.xml
引入约束
!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”
http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd”>

在session-factory的标签下手动配置如下信息
<session-factory>
		<!-- 必须配置 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///ssh_all</property>
<property name="hibernate.connection.username">数据库(root)</property>
<property name="hibernate.connection.password">123456(密码)</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 可选配置 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 映射配置文件 -->
	<mapping resource="(自己手动引入Javabean.hbm.xml)"/>
	</session-factory>

在src目录下 Javabean所在包的下面创建例如xxxxxx.hbm.xml文件 同样需要引入约束

然后手动配置如下信息
<class name="org.vector.domain.Customer(Javabean的全路径)" table="cst_customer(数据库表名字)">
	<!-- name属性是Javabean中的主键 column是表中的主键 -->
	<id name="cust_id" column="cust_id">
		<generator class="native"/>
	</id>
	<!-- 把Javabean中的字段写入到下方 -->
	<property name="cust_name" column="cust_name"/>
	<property name="cust_user_id" column="cust_user_id"/>
	
</class>

创建Struts.xml文件放在项目的src目录下
<?xml version="1.0" encoding="UTF-8" ?>
创建spring的配置文件applicationContext.xml 放在项目的src目录下 依旧是先引入约束
	<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx.xsd">
直接复制进去
<!-- 编写bean,名称都是固定,加载hibernate.cfg.xml的配置文件 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
	<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>

<!-- 先配置平台事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 开启事务的注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 以后配置Action 必须是多例的 -->
<bean id="customerAction" class="org.vector.web.action.CustomerAction" scope="prototype">
	<property name="customerService" ref="customerService"/>
</bean>
<!-- 配置service -->
<bean id="customerService" class="org.vector.serviceImpl.CustomerServiceImpl">
<!-- 注入serviceImpl -->
	<property name="customerDao" ref="customerDao"></property>
</bean>
<!-- 配置dao -->
<bean id="customerDao" class="org.vector.daoImpl.CustomerDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>‘’

自己根据情况修改name class ref 等属性
接着配置web.xml文件中的web监听器

org.springframework.web.context.ContextLoaderListener


contextConfigLocation
classpath:applicationContext.xml

ssh框架的环境已经搭建成功
在这里插入图片描述

希望大佬多多指教 小萌新路过

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值