ssm

  1. SSM集成

如果要做三大框架集成,我们先保证在一个项目,每一个框架都能够独立运行!!

Spring :管理整个项目

Springmvc:mvc的框架

 Mybatis:orm

 

spring-MVC

applicationContext-mvc.xml

 

 

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3 xmlns:context="http://www.springframework.org/schema/context"
 4 xmlns:mvc="http://www.springframework.org/schema/mvc"
 5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6 xsi:schemaLocation="http://www.springframework.org/schema/beans
 7 http://www.springframework.org/schema/beans/spring-beans.xsd
 8 http://www.springframework.org/schema/context
 9 http://www.springframework.org/schema/context/spring-context.xsd
10 http://www.springframework.org/schema/mvc
11 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
12 <!-- 放行核心控制器对静态资源的拦截 -->
13 <mvc:default-servlet-handler/>
14 <!-- 支持springmvc注解驱动 -->
15 <mvc:annotation-driven/>
16 <!-- 配置扫描器 -->
17 <context:component-scan base-package="com.wz"></context:component-scan>
18 <!-- 配置上传下载     下决心者,解决[答]问题者 -->
19 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
20     <property name="maxUploadSize">
21         <value>200000</value>
22     </property>
23 </bean>
24 </beans>

applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!-- spring的配置文件 -->
 3 <beans xmlns="http://www.springframework.org/schema/beans"
 4 xmlns:context="http://www.springframework.org/schema/context"
 5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6 xsi:schemaLocation="http://www.springframework.org/schema/beans
 7 http://www.springframework.org/schema/beans/spring-beans.xsd
 8 http://www.springframework.org/schema/context
 9 http://www.springframework.org/schema/context/spring-context.xsd">
10 <!--在spring文件中配置db.properties -->
11 <context:property-placeholder location="classpath:db.properties"/>
12 <!-- 配置连接池对象 -->
13 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
14 <property name="driverClassName" value="${jdbc.driverClassName}"/>
15         <property name="url" value="${jdbc.url}"/>
16         <property name="username" value="${jdbc.username}"/>
17         <property name="password" value="${jdbc.password}"/>
18     </bean>
19 <!-- 配置mybatis的核心对象 sqlsessionFactory -->
20 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
21 <property name="dataSource" ref="dataSource"/>
22 <!--加载所有的mapper路径-->
23 <property name="mapperLocations" value="classpath:com/wz/domain/*Mapper.xml"/>
24 </bean>
25 <!-- 配置mappper接口对象 -->
26 <!-- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
27 <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
28 <property name="mapperInterface" value="com.wz.mapper.ProductMapper"/>
29 </bean>
30 
31 <bean id="pruductMappetr" class="org.mybatis.spring.mapper.MapperFactoryBean">
32 <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
33 <property name="mapperInterface" value="com.wz.mapper.ProductMapper"/>
34 </bean> -->
配置所有的mapper接口:一劳永逸 35 <!-- 配置一个包的路径spring会自动扫描该包下的所有接口,并为其自动生成接口对象 --> 36 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 37 <property name="basePackage" value="com.wz.mapper"/> 38 </bean> 39 40 </beans>

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 3   <display-name>day53ssm</display-name>
 4   <welcome-file-list>
 5     <welcome-file>index.html</welcome-file>
 6     <welcome-file>index.htm</welcome-file>
 7     <welcome-file>index.jsp</welcome-file>
 8     <welcome-file>default.html</welcome-file>
 9     <welcome-file>default.htm</welcome-file>
10     <welcome-file>default.jsp</welcome-file>
11   </welcome-file-list>
12   <!-- 配置的全局的变量 contextConfigLocation = classpath:applicatinContext.xml -->
13   <context-param>
14   <param-name>contextConfigLocation</param-name>
15   <param-value>classpath:applicationContext.xml</param-value>
16   </context-param>
17   <!-- 在启动服务器时加载spring的配置文件 -->
18   <listener>
19   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
20  
21  <!--  配置post请求的乱码问题 -->
22   </listener>
23   <filter>
24   <filter-name>CharacterEncodingFilter</filter-name>  
25   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
26   <init-param>
27          <param-name>encoding</param-name>
28          <param-value>UTF-8</param-value>
29      </init-param>
30   
31   </filter>
32   <filter-mapping>
33   <filter-name>CharacterEncodingFilter</filter-name>
34   <url-pattern>/*</url-pattern>
35   </filter-mapping>
36    <!-- 配置springmvc核心控制器 -->
37   <servlet>
38   <servlet-name>dispatcherServlet</servlet-name>
39   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
40   <init-param>
41   <param-name>contextConfigLocation</param-name>
42   <param-value>classpath:applicationContext-mvc.xml</param-value>
43   </init-param>
44   </servlet>
45   
46   <servlet-mapping>
47   <servlet-name>dispatcherServlet</servlet-name>
48   <url-pattern>/</url-pattern>
49   </servlet-mapping>
50   
51   
52   
53 </web-app>
原文地址:https://www.cnblogs.com/wzscom/p/10549668.html