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
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!--
③:对模型视图名称的解析,即在模型视图名称添加前后缀
-->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" 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"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>
<!--配置一个数据源,根据上面propertyConfig指定的location去找数据库连接的配置信息-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
<!--根据dataSource和configLocation创建一个SqlMapClient-->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>/WEB-INF/SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!--根据sqlMapClien创建一个SqlMapClient模版类-->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</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>
自此配置文件组装完成。
学习历程艰苦,请加油!
分享到:
相关推荐
springmvc+spring+ibatis 整合 内含 数据库初始化 显示用了DHTMLX
springMVC+spring+ibatis 整合,包含初始化sql 为myeclipse项目,数据库配置见properites文件
spring+springMVC+iBatis+Json整合所需jar包
springmvc+spring+ibatis框架搭建步骤(注解方式)
前段时间自己研究了下SpringMVC,发现资源很少。经过自己的努力,整合了一套出来。
为最初学习spring+springMVC+ibatis的同学提供一个简单的参考示例
spring+springmvc+ibatis的整合例子,适合新手入门,简单明了
springMVC+Velocity+iBATIS的整合小demo
SpringMVC+ibatis+velocity整合例子,虽然比较简单。可以为没有配置好的同学作为参考。
项目需要,可直接拿来用。本人花了一个礼拜心血搞的。有点,如果是发布到tomcat55上面可能要删掉验证xml的jar包才能正确运行
springmvc+ibatis +maven多项目整合
Spring + SpringMVC + Myibatis + Druid 整合源码,修改log4j.properties中log4j.appender.A1.File=YOUR-LOG-PATH,log4j.appender.FILE.File=YOUR-LOG-FILE
Spring MVC+ibatis+Oracle资源整合,实现简单的增删改查
Spring+ibatis+struts框架整合+springmvc数据接口封装含数据表可直接运行
maven 整合spring springmvc ibatis
spring+springMvc+Ibatis整合,增删改查,附带lib包。网上很多例子大多不全。这个项目物有所值。
springMVC spring ibatis整合jar
此案例有springMVC整合ibatis包含了springMVC的注解使用 spring管理ibatis的详细配置
ibatis spring springmvc 整合 integrate
spring , MVC, Ibatis, 整合