首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

springMVC+spring+ibatis调整

2012-07-05 
springMVC+spring+ibatis整合1:web.xml如下:?xml version1.0 encodingUTF-8?web-app xmlns:xsi

springMVC+spring+ibatis整合
1:web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>wanmeiheti</display-name>

<!-- Spring 容器启动监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring 服务层的配置文件,依靠这个找到applicationContext.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!--
Spring MVC 的Servlet,它将加载WEB-INF/app-servlet.xml 的 配置文件,以启动Spring
MVC模块
-->
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>


2:跟web.xml对应的需要app-serlet.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<!-- ①:对com.zh包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.zh" />
<!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean
/>
<!--
③:对模型视图名称的解析,即在模型视图名称添加前后缀
-->
<bean
value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
    </bean>
</beans>


3:spring配置文件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: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/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byType">

<context:annotation-config />
<context:component-scan base-package="com.zh" />

<!--此bean告诉Spring去哪找数据库的配置信息,因为有此Bean才出现下面用${}标记来取变量的语句-->
<bean id="propertyConfig"
/>
</property>
</bean>

<!--根据sqlMapClien创建一个SqlMapClient模版类-->
<bean id="sqlMapClientTemplate" />
</property>
</bean>
</beans>


4:spring需要的数据库配置信息 jdbc.properties

jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.url=jdbc:jtds:sqlserver://127.0.0.1:1433/zh
jdbc.username=sa
jdbc.password=


5:ibatis配置文件 SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="/com/zh/model/stu.xml" />
</sqlMapConfig>

自此配置文件组装完成。

学习历程艰苦,请加油!




热点排行