SSH整合(Struts2.3.7 + Spring3.2.0 + Hibernate4.1.9)

本文详细介绍了如何在Windows环境下通过整合Spring、Struts、MySQL等技术构建Web应用的过程,包括环境配置、核心文件配置以及关键组件的引入与使用。旨在帮助开发者快速上手并深入理解各组件之间的交互与作用。

一、整合环境:window7 + Tomcat6 + MySQL5.1

二、需要的jar:相应的jar包,视功能而定。既然是学习,就应该自己尝试,这样就更熟悉每个jar包的作用。

三、各个文件配置:

1.WEB-INF/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://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

	<display-name>mySystem</display-name>

	<!-- 指定spring的配置文件,默认从web根目录寻找,我们可以通过spring提供的classpath:前缀来指定从类路径下寻找 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext*.xml</param-value>
	</context-param>

	<!-- Spring上下文监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- struts2拦截器 -->
	<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>

	<!-- Session时间配置(单位:分钟) -->
	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>

	<!-- 登陆页面 -->
	<welcome-file-list>
		<welcome-file>/index.jsp</welcome-file>
	</welcome-file-list>

</web-app>

2.src/struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!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.i18n.encoding" value="UTF-8"></constant> <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
	<constant name="struts.serve.static.browserCache" value="false" /> <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
	<constant name="struts.configuration.xml.reload" value="true" /> <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
	<constant name="struts.ui.theme" value="simple"></constant> <!-- 默认的视图主题 -->
	<constant name="struts.multipart.saveDir" value="E:/temp"></constant> <!-- 文件上传时的临时目录 -->
	<constant name="struts.multipart.maxSize" value="1048576000" /> <!-- 文件上传时的最大值 (单位:k) -->
	<constant name="struts.objectFactory" value="spring" /> <!-- 使用spring的工厂去替换Struts2的默认工厂,也就是Action由spring来创建和维护 -->
	<constant name="struts.action.extension" value="action" /> <!-- 拦截的后缀名 -->
	
	<include file="struts-default.xml" /> <!-- 导入默认的xml配置文件 -->

	<!-- 定义全局的配置设置 -->
	<package name="struts-main" extends="struts-default">
		<interceptors>
			<!-- Session拦截器 -->
			<interceptor name="sessionTimeOut" class="com.bao.utils.interceptors.SessionInterceptor" />
			<!-- 去除页面参数字符串两端的空格拦截器 -->
			<interceptor name="trimInterceptor" class="com.bao.utils.interceptors.TrimInterceptor" />
			<!-- 定义拦截器栈 -->
			<interceptor-stack name="baseStack">
							
				<interceptor-ref name="defaultStack" /> <!-- 系统默认的拦截器,必须要有 -->
			</interceptor-stack>
		</interceptors>
		<default-interceptor-ref name="baseStack" /> <!-- 配置默认拦截器栈 -->

		<!-- 全局配置 -->
		<global-results>
			<result name="error">/WEB-INF/admin/error.jsp</result>
			<result name="success">/WEB-INF/admin/success.jsp</result>
		</global-results>
	</package>

	<!-- 引用功能模块对应的Struts配置文件 -->
	<include file="com/bao/admin/admin_struts.xml"></include>

</struts>

3.src/applicationContext.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"
	xsi:schemaLocation="
			http://www.springframework.org/schema/beans
			http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/context
			http://www.springframework.org/schema/context/spring-context-2.5.xsd
			http://www.springframework.org/schema/aop
			http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			http://www.springframework.org/schema/tx
			http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
			
	<!-- 启用扫描功能:扫描+注解的方式,把bean交给Spring管理 -->
	<context:component-scan base-package="com.bao" />
	<!-- 加载JDBC的配置文件 -->
	<context:property-placeholder location="classpath:jdbc.properties" />
	<!-- 配置C3p0数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="${driverClass}" />
		<property name="jdbcUrl" value="${jdbcUrl}" />
		<property name="user" value="${user}" />
		<property name="password" value="${password}" />
		
		<!-- 每60秒检查所有连接池中的空闲连接。Default: 0 -->
		<property name="idleConnectionTestPeriod" value="60" />
		<!-- 初始化时获取的链接数,取值应在minPoolSize与maxPoolSize之间。Default:3 -->
		<property name="initialPoolSize" value="3" />
		<!-- 连接池中保留的最小连接数。Default:2 -->
		<property name="minPoolSize" value="2" />
		<!-- 连接池中保留的最大连接数。Default:15 -->
		<property name="maxPoolSize" value="15" />
		<!-- 最大空闲时间,120秒内未使用则连接被丢弃。若为0则永不丢弃。Default:0 -->
		<property name="maxIdleTime" value="120" />
		<!-- 当连接池中的连接耗尽时,c3p0一次同时获取的连接数。Default:3 -->
		<property name="acquireIncrement" value="3" />
	</bean>
		
	<!-- Hibernate 配置 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mappingResources">
			<list>
				<value>com/bao/admin/bean/Admin.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<value>
				hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
				hibernate.hbm2ddl.auto=update
				hibernate.show_sql=true
				hibernate.format_sql=false
			</value>
		</property>
	</bean>
	
	<!-- 配置事务管理器,以使用Spring提供的事务管理功能 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<!-- 使用基于注解方式来配置事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

</beans>


4.src/jdbc.properties:

driverClass=org.gjt.mm.mysql.Driver
jdbcUrl=jdbc:mysql://localhost:3306/mysystem?useUnicode=true&characterEncoding=UTF-8
user=root
password=123456


5.参考文档:http://txazo.iteye.com/blog/1669771 点击打开链接

说明:其它的实体类和Hibernate的映射文件,并没有给出,是为了逼自己学习更多的知识!

ps:其实查看官方文档并没有想像中的难,即使英语再差,当学习到一定的时候就应该逼着自己看看的官方文档,不能总是看已经翻译好的文档,这样才能提升自己的能力!

源码链接: https://pan.quark.cn/s/a4b39357ea24 银行信贷业务作为银行业务的关键构成部分,涵盖了银行向客户提供的各类融资服务,例如贷款、担保以及信用证等。此类业务致力于协助企业与个人解决资金需求问题,进而推动经济活动的开展。银行通过信贷业务获取利息收入,同时需承担相应风险,以保障资金的稳定与流转。 **信贷定义** 信贷意味着银行运用自身资本及信誉为客户提供资金支持,而客户则需以支付利息、费用并偿还本金为前提条件。这种业务模式不仅包含直接贷款,还包括为客户的债务承担提供担保。依照会计准则,信贷业务可分为表内业务与表外业务,前者对银行的资产负债表产生直接影响,后者则不直接关联。 **信贷业务划分标准** 1. **依据会计核算归属**:表内信贷(如贷款、贴现)和表外信贷(如承兑、保证)。 2. **根据期限划分**:短期(不超过1年)、中期(1至5年)与长期(超过5年)。 3. **按照担保方式分类**:信用信贷(无担保)和担保信贷(保证、抵押、质押)。 4. **按照币种区分**:本币信贷与外币信贷。 5. **按照性质和用途区分**:固定资产贷款、流动资金贷款、循环额度贷款、消费贷款等。 6. **按照贷款组织形式区分**:普通贷款、联合贷款和银团贷款。 7. **按照资金来源区分**:信贷资金贷款、委托贷款和境外筹资转贷款。 8. **按照授信对象区分**:公司类信贷与个人类信贷。 **信贷业务产品** 1. **流动资金贷款**:用于企业日常运营周转或临时性资金需求。 2. **固定资产贷款**:用于投资固定资产项目。 3. **房地产开发贷款**:用于土地开发及房屋建设所需资金。 4. **循环额度贷款**:满足企业...
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值