1.struts1的配置文件--struts-config.xml
2.struts2的配置文件
3.hibernate的配置文件-- hibernate.cfg.xml
4.hibernate的映射文件
5.ibatis的配置文件
6.ibatis的映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!-- struts-config文件中个元素必须按此顺序写入,否则会引发错误 -->
<struts-config>
<!--连接数据库, -->
<data-sources>
<data-source>
<!-- 所用的JDBC驱动类,必须-->
<set-property property="driverClass" value="com.mysql.jdbc.Driver" />
<!-- 所用的JDBC的URL,必须-->
<set-property property="url" value="jdbc:mysql://localhost/test" />
<!-- 连结到数据库的用户名,必须-->
<set-property property="user" value="root" />
<!-- 连结到数据库的密码,必须-->
<set-property property="password" value="root" />
<!-- 同时打开的最小连结数,缺省值为1,可选-->
<set-property property="minCount" value="1" />
<!-- 同时打开的最大连结数,缺省值为2,可选-->
<set-property property="maxCount" value="5" />
</data-source>
</data-sources>
<!-- 配置Action中对应的FormBean -->
<form-beans>
<form-bean name="userinfoForm" type="com.bbs.web.struts.form.UserinfoForm" />
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="newtopic" path="/forum/newtopic.jsp" />
</global-forwards>
<action-mappings>
<!--
path : Action请求的相对路径
input : 当Bean发生错误时返回的路径(可选)
name : 该Action绑定的FormBean,对应form-bean元素中定义的name
parameter :
type: 该Action的对应类的全路径
validate : 是否调用ActinoForm的validate()方法,默认为true
forward : 指定处理相应请求所对应的地址
-->
<action path="/usermanager" input="/user/register.jsp" name="userinfoForm"
scope="request" validate="true"
type="com.bbs.web.struts.action.UserAction">
<forward name="userlist" path="/admin/manager.jsp" />
</action>
</action-mappings>
<!-- 定义资源文件-->
<message-resources parameter="com.bbs.struts.ApplicationResources" />
</struts-config>
2.struts2的配置文件
<?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>
<!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 设置浏览器是否缓存静态内容,默认值为true,开发期间最好设为false-->
<constant name="struts.serve.static.browserCache " value="false" />
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false,开发期间最好true -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 开发模式下设为true,这样可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="true" />
<!--
namespace : 命名空间,使用时需要用命名空间+result的name值
action元素中method : 调用Action中的方法名,默认为execute方法
-->
<package name="actions" extends="struts-default" namespace="/actions">
<action name="Student*" class="com.whm.UserAction" method="test">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
3.hibernate的配置文件-- hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- SQL方言,这个是MySQL的 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 数据库连接池 -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- 一次读的数据库记录数 -->
<property name="jdbc.fetch_size">50</property>
<!--是否把SQL语句输入到控制台 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!--
-->
<!-- 映射类,用annotation时候用到 -->
<mapping class="com.whm.User"/>
<!-- 映射文件 -->
<mapping resource="com/whm/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
4.hibernate的映射文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.whm.User" table="user">
<!-- 主键 -->
<composite-id name="pk">
<key-property name="id"></key-property>
</composite-id>
<!-- name对应类中的字段 ,type表示数据类型-->
<property name="age" />
<property name="sex" type="char"/>
</class>
</hibernate-mapping>
5.ibatis的配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<!-- Always ensure to use the correct XML header as above! -->
<!-- ibatis配置文件 -->
<sqlMapConfig>
<!--
The properties (name=value) in the file specified here can be used
placeholders in this config file (e.g. “${driver}”. The file is
relative to the classpath and is completely optional.
-->
<!-- SQL Map配置文件拥有唯一的properties文件 -->
<properties resource="jdbc.properties" />
<!--
These settings control SqlMapClient configuration details, primarily
to do with transaction management. They are all optional (more detail
later in this document).
-->
<!-- useStatementNamespaces 是允许使用namespace ,默认为false-->
<settings cacheModelsEnabled="true" enhancementEnabled="true"
lazyLoadingEnabled="true" maxRequests="32" maxSessions="10"
maxTransactions="5" useStatementNamespaces="true" />
<!-- 当某个类名较长的时候可以使用此还定义一个alias -->
<typeAlias alias="shortname" type="com.long.class.path.Class" />
<!--
Configure a datasource to use with this SQL Map using
SimpleDataSource. Notice the use of the properties from the above
resource
-->
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}" />
<property name="JDBC.ConnectionURL" value="${url}" />
<property name="JDBC.Username" value="${username}" />
<property name="JDBC.Password" value="${password}" />
<property name="JDBC.DefaultAutoCommit" value="true" />
<property name="Pool.MaximumActiveConnections" value="10" />
<property name="Pool.MaximumIdleConnections" value="5" />
<property name="Pool.MaximumCheckoutTime" value="120000" />
<property name="Pool.TimeToWait" value="500" />
<property name="Pool.PingQuery" value="select 1 from ACCOUNT" />
<property name="Pool.PingEnabled" value="false" />
<property name="Pool.PingConnectionsOlderThan" value="1" />
<property name="Pool.PingConnectionsNotUsedFor" value="1" />
</dataSource>
</transactionManager>
<!--
Identify all SQL Map XML files to be loaded by this SQL map. Notice
the paths are relative to the classpath. For now, we only have one…
-->
<!-- CLASSPATH RESOURCES -->
<sqlMap resource="com/whm/db/sqlmap/UserInfoSqlMap.xml" />
<!-- URL RESOURCES -->
<sqlMap url="file:///c:/config/UserInfoSqlMap.xml" />
</sqlMapConfig>
6.ibatis的映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="USERINFO">
<resultMap class="com.whm.db.dto.UserDto" id="resultMap">
<result property="country" column="COUNTRY"/>
</resultMap>
<parameterMap class="com.whm.db.dto.UserDto" id="parameterMap">
<parameter property="username"/>
<parameter property="country"/>
</parameterMap>
<select id="SELECT010" resultMap="resultMap" parameterMap="parameterMap">
SELECT
COUNTRY
FROM
USER
WHERE
USERNAME like '%$username$%'
AND
TRIM(COUNTRY) = #country#
</select>
<select id="SELECT020" resultClass="java.lang.String" parameterClass="com.whm.db.dto.UserDto">
SELECT
USERNAME,
PASSWORD
FROM
USER
<dynamic prepend="WHERE">
<isNotNull id="country" prepend="AND">
COUNTRY = #country#
</isNotNull>
</dynamic>
order by $preferedOrder$
</select>
</sqlMap>
7.spring的配置文件
<?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">
<context:annotation-config />
<context:component-scan base-package="com.whm" />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.whm.model</value>
</list>
</property>
<!--
<property name="annotatedClasses">
<list>
<value>com.whm.model.User</value>
<value>com.whm.model.Log</value>
</list>
</property>
-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.whm.service..*.*(..))" />
<aop:advisor pointcut-ref="bussinessService"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="getUser" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>