<span style="font-family: Arial, Helvetica, sans-serif;">.</span><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">首先看环境的搭建</span>
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">
<!-- 装载spring 的配置文件包括应用层,DAO层 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml,classpath:daoContext.xml
</param-value>
</context-param>
<!-- 装载log4j的配置内容 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<!-- 此处必须注意地址标志位置,以免错误!! 默认编译后class文件存储位置-->
<param-value>classpath:log4j.properties</param-value>
</context-param>
<!-- 当多个项目时每个项目的webAppRootKey必须不一样 -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>MyTestProject.root</param-value>
</context-param>
<!-- 定义编码过滤器,当发送请求时过此过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- SpringMVC 分派器及相关映射 默认去找WEB-NIF目录下的dispatcher-servelt.xml文件-->
<!-- 即收到请求后去找那个文件 -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!--Spring ApplicationContext 载入 通过此监听器启动加载spring配置文件 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<!-- 支持session scope的Spring bean -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
</web-app>
然后是
daoContext.xml.和dispathcer.xml的配置
daoContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 此bean用于从外部属性文件载入属性,并使用这些属性值替换spring配置文件中的占位符变量 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/jdbc.properties</value>
</list>
</property>
</bean>
<!-- 定义数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${driver}</value>
</property>
<property name="url">
<value>${url}</value>
</property>
<property name="username">
<value>${username}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
</bean>
<!-- 定义sqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<!-- 加载ibatis的配置文件 -->
<property name="configLocation">
<value>classpath:sql-map-config.xml</value>
</property>
<!-- 加载数据源 -->
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!-- 各个实现增删改查的bean -->
<bean id="CustomerDao" class="com.test.dao.CustomerDaoTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id="MchtOrderDao" class="com.test.dao.MchtOrderDaoTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient"/>
</property>
</bean>
<bean id="BankCardDao" class="com.test.dao.BankCardDaoTemplate" >
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
</beans>
dispathcer.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-autowire="byName">
<!-- SpringMVC相关Bean配置 -->
<!-- View Resolver 视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 将不同的URL映射到对应的控制器 -->
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="bank.action">bankController</prop>
</props>
</property>
</bean>
</beans>
今天先写到这,明天继续补,,,,