1、開發環境:MyEclipse、MySQL、jdk1.7.0_79、Tomcat 7.x
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICdzFWRoRXdvN1LclHdpZXYyd2LcBzNvwVZ2x2bzNXak9CX90TQNNkRrFlQKBTSvwFbslmZvwFMwQzLcVmepNHdu9mZvwFVywUNMZTY18CX052bm9CX9kkeNJzaE9EerpXTmZEWjZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39zMxUjNyAzMxETMzATM3EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
2、建立資料庫
3、建立資料庫連結配置檔案(db.properties)
datasource.driverClassName=com.mysql.jdbc.Driver
#資料庫連結位址
datasource.url=jdbc\:mysql\:///empmanage
datasource.username=資料庫連結使用者
datasource.password=資料庫連結密碼
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.cache.class=org.hibernate.cache.EhCacheProvider
hibernate.cache.query=false
c3p0.maxPoolSize=
c3p0.minPoolSize=
c3p0.initialPoolSize=
c3p0.maxIdleTime=
c3p0.acquireIncrement=
c3p0.acquireRetryAttempts=
c3p0.acquireRetryDelay=
c3p0.autoCommitOnClose=false
dbcp.initialSize=
dbcp.maxIdle=
dbcp.minIdle=
dbcp.maxActive=
dbcp.logAbandoned=true
dbcp.removeAbandoned=true
dbcp.removeAbandonedTimeout=
dbcp.maxWait=
#set to 'SELECT 1'
dbcp.validationQuery = "SELECT 1"
#set to 'true'
dbcp.testWhileIdle = true
#some positive integer
dbcp.timeBetweenEvictionRunsMillis =
#set to something smaller than 'wait_timeout'
dbcp.minEvictableIdleTimeMillis =
#if you don't mind a hit for every getConnection(), set to "true"
dbcp.testOnBorrow = "true"
scheduler.Manager = false
date=
4、struts.properties 檔案
struts.action.extension=do,tg,action
struts.objectFactory=spring
#struts.enable.DynamicMethodInvocation=false
struts.devMode=false
struts.locale=zh_CN
struts.i18n.encoding=utf-
struts.multipart.maxSize=
5、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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.user.**"></context:component-scan>
<!-- 導入資源檔案 -->
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${datasource.driverClassName}"></property>
<property name="url" value="${datasource.url}"></property>
<property name="username" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="300" />
<property name="timeBetweenEvictionRunsMillis" value="86400" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="SELECT 1 FROM dual" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan">
<list>
<value>com.user.**.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.default_batch_fetch_size">4</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="alter*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="set*" propagation="REQUIRED"/>
<tx:method name="register" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="process*" propagation="REQUIRED"/>
<tx:method name="restore*" propagation="REQUIRED"/>
<tx:method name="backup*" propagation="REQUIRED"/>
<tx:method name="log*" propagation="REQUIRED"/>
<tx:method name="giving*" propagation="REQUIRED"/>
<tx:method name="auth*" propagation="REQUIRED"/>
<tx:method name="sendMessage*" propagation="REQUIRED"/>
<tx:method name="cust*" propagation="REQUIRED"/>
<tx:method name="make*" propagation="REQUIRED"/>
<tx:method name="inq*" propagation="REQUIRED"/>
<tx:method name="list*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="(execution(* com.user..*Service.*(..)))" id="pointcut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>
</beans>
6、web.xml檔案
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<display-name></display-name>
<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>
<filter>
<filter-name>openSessionInViewerFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewerFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</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>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
增、删、查、改的實作參考(http://blog.csdn.net/qq_39189632/article/details/78404536)
到這裡我們的架構配置結束了,如果對你有幫助,請關注我。有不明白的可以留言…..
原碼下載下傳:http://download.csdn.net/download/qq_39189632/10046918