SSM整合思路

Spring MVC是Spring框架中的一个模块,所以Spring MVC与Spring之间不存在整合的问题,只要引入相应JAR包就可以直接使用。因此SSM框架的整合就只涉及到了Spring与MyBatis的整合,以及Spring MVC与MyBatis的整合。Spring与MyBatis框架的整合时,通过Spring实例化Bean,然后调用实例对象中的查询方法来执行MyBatis映射文件中的SQL语句的,如果能够正确查询出数据库中的数据,那么就可以认为Spring与MyBatis框架整合成功。加入Spring MVC后,如果可以通过前台页面来执行查询方法,并且查询出的数据能够在页面中正确显示,那么就可以认为三大框架整合成功。

1、dao层
  1.1、必须数据:
       pojo(java实体)、mapper接口(dao接口)、sql映射文件(翻译为jdbc中的statement)
  1.2、配置文件:
       mybatis核心配置文件:SqlMapConfig.xml
          自定义别名
       spring整合mybatis配置文件:applicationContext-dao.xml
         数据源
         会化工厂
         mapper扫描(加载dao)
       其他配置:
         数据库信息:db.properties
         日志信息:log4j.properties
2、service层
  2.1、配置文件:
       注解扫描:@service(加载service)applicationContext-service.xml
       事务配置: ApplicationContext-trans.xml
3、controller层
  3.1、配置文件: springMVC.xml
       注解扫描:@controller(加载controller)
       注解驱动:自动加载最新的处理器映射器、处理器适配器
       视图解析器:
       自定义类型转化器:(挂载于注解驱动)
       文件上传解析器:
       json格式数据解析器:(若没有配置注解驱动,则需要显示的在处理器适配器挂载)
       全局异常处理器:
       自定义拦截器:
       静态资源放行:
       
4、web.xml web.xml
  4.1、spring监听器
  4.2、springMVC前端控制器
  4.3、post中文乱码请求

SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <properties resource="db.properties"></properties>
<span class="hljs-tag">&lt;<span class="hljs-title">typeAliases</span>&gt;</span> 
    <span class="hljs-comment">&lt;!-- 定义单个pojo类别名
            type:类的全路劲名称
            alias:别名
     --&gt;</span>
    <span class="hljs-comment">&lt;!-- &lt;typeAlias type="xx.xxxx.pojo.User" alias="user"/&gt; --&gt;</span>

    <span class="hljs-comment">&lt;!-- 使用包扫描的方式批量定义别名 
    定以后别名等于类名,不区分大小写,但是建议按照java命名规则来,首字母小写,以后每个单词的首字母大写
    --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">package</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"xx.xxx.pojo"</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">typeAliases</span>&gt;</span>

</configuration>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

applicationContext-dao.xml

<beansxmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<span class="hljs-comment">&lt;!-- 配置 读取properties文件 jdbc.properties --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">context:property-placeholderlocation="classpath:jdbc.properties"</span>/&gt;</span>

<span class="hljs-comment">&lt;!-- 配置 数据源 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">beanid="dataSource"class="com.alibaba.druid.pool.DruidDataSource"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 驱动 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="driverClassName"value="${jdbc.driver}"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- url --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="url"value="${jdbc.url}"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- 用户名 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="username"value="${jdbc.username}"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- 密码 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="password"value="${jdbc.password}"</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 配置 Mybatis的工厂 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">beanclass="org.mybatis.spring.SqlSessionFactoryBean"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 数据源 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="dataSource"ref="dataSource"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- 配置Mybatis的核心 配置文件所在位置 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="configLocation"value="classpath:SqlMapConfig.xml"</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- 配置pojo别名 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="typeAliasesPackage"value="xx.xxxx.core.bean"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 配置 1:原始Dao开发 接口实现类 Mapper.xml 三个 2:接口开发 接口 不写实现类 Mapper.xml 二个 (UserDao、ProductDao 
    、BrandDao。。。。。。。) 3:接口开发、并支持扫描 xx.xxxx.core.dao(UserDao。。。。。) 写在此包下即可被扫描到 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">propertyname="basePackage"value="xx.xxxx.core.dao"</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

</beans>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/springmvc?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
 
  • 1
  • 2
  • 3
  • 4

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

ApplicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    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-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<span class="hljs-comment">&lt;!-- @Service扫描 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">context:component-scan</span> <span class="hljs-attribute">base-package</span>=<span class="hljs-value">"xx.xxxxx.service"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">context:component-scan</span>&gt;</span>

</beans>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

ApplicationContext-trans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    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-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<span class="hljs-comment">&lt;!-- 事务管理器 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">"transactionManager"</span>
    <span class="hljs-attribute">class</span>=<span class="hljs-value">"org.springframework.jdbc.datasource.DataSourceTransactionManager"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 数据源 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"dataSource"</span> <span class="hljs-attribute">ref</span>=<span class="hljs-value">"dataSource"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 通知 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">tx:advice</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">"txAdvice"</span> <span class="hljs-attribute">transaction-manager</span>=<span class="hljs-value">"transactionManager"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">tx:attributes</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- 传播行为 --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"save*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"REQUIRED"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"insert*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"REQUIRED"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"delete*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"REQUIRED"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"update*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"REQUIRED"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"find*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"SUPPORTS"</span> <span class="hljs-attribute">read-only</span>=<span class="hljs-value">"true"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"get*"</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">"SUPPORTS"</span> <span class="hljs-attribute">read-only</span>=<span class="hljs-value">"true"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">tx:attributes</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">tx:advice</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 切面 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">aop:config</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">aop:advisor</span> <span class="hljs-attribute">advice-ref</span>=<span class="hljs-value">"txAdvice"</span>
        <span class="hljs-attribute">pointcut</span>=<span class="hljs-value">"execution(* xx.xxxx.service.*.*(..))"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">aop:config</span>&gt;</span>

</beans>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

SpringMvc.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"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<span class="hljs-comment">&lt;!-- @Controller注解扫描 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">context:component-scan</span> <span class="hljs-attribute">base-package</span>=<span class="hljs-value">"xx.xxxx.controller"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">context:component-scan</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 注解驱动:
        替我们显示的配置了最新版的注解的处理器映射器和处理器适配器 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">mvc:annotation-driven</span> <span class="hljs-attribute">conversion-service</span>=<span class="hljs-value">"conversionService"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">mvc:annotation-driven</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 配置视图解析器 
作用:在controller中指定页面路径的时候就不用写页面的完整路径名称了,可以直接写页面去掉扩展名的名称
--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"org.springframework.web.servlet.view.InternalResourceViewResolver"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 真正的页面路径 =  前缀 + 去掉后缀名的页面名称 + 后缀 --&gt;</span>
    <span class="hljs-comment">&lt;!-- 前缀 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"prefix"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"/WEB-INF/jsp/"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 后缀 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"suffix"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">".jsp"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 配置自定义转换器 
注意: 一定要将自定义的转换器配置到注解驱动上
--&gt;</span>
<span class="hljs-comment">&lt;!--&lt;bean id="conversionService"
    class="org.springframework.format.support.FormattingConversionServiceFactoryBean"&gt;
    &lt;property name="converters"&gt;
        &lt;set&gt;
            &amp;lt;!&amp;ndash; 指定自定义转换器的全路径名称 &amp;ndash;&amp;gt;
            &lt;bean class="xx.xxxx.controller.converter.CustomGlobalStrToDateConverter"/&gt;
        &lt;/set&gt;
    &lt;/property&gt;
&lt;/bean&gt;--&gt;</span>

<span class="hljs-comment">&lt;!-- 配置全局异常处理器 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"xx.xxxx.exception.CustomGlobalExceptionResolver"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 文件上传 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">"multipartResolver"</span>
    <span class="hljs-attribute">class</span>=<span class="hljs-value">"org.springframework.web.multipart.commons.CommonsMultipartResolver"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 设置上传文件的最大尺寸为5MB --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"maxUploadSize"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">value</span>&gt;</span>5242880<span class="hljs-tag">&lt;/<span class="hljs-title">value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 在注解适配器中加入messageConverters --&gt;</span>
<span class="hljs-comment">&lt;!-- 注意:如果使用&lt;mvc:annotation-driven /&gt; 则不用定义下面的内容。--&gt;</span>
<span class="hljs-comment">&lt;!--&lt;bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"&gt;--&gt;</span>
    <span class="hljs-comment">&lt;!--&lt;property name="messageConverters"&gt;--&gt;</span>
        <span class="hljs-comment">&lt;!--&lt;list&gt;--&gt;</span>
            <span class="hljs-comment">&lt;!--&lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;&lt;/bean&gt;--&gt;</span>
        <span class="hljs-comment">&lt;!--&lt;/list&gt;--&gt;</span>
    <span class="hljs-comment">&lt;!--&lt;/property&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--&lt;/bean&gt;--&gt;</span>


<span class="hljs-comment">&lt;!-- 配置拦截器 --&gt;</span>
<span class="hljs-comment">&lt;!--&lt;mvc:interceptors&gt;
    &lt;mvc:interceptor&gt;
        &amp;lt;!&amp;ndash; 拦截请求的路径    要拦截所有必需配置成/** &amp;ndash;&amp;gt;
        &lt;mvc:mapping path="/**"/&gt;
        &amp;lt;!&amp;ndash; 指定拦截器的位置 &amp;ndash;&amp;gt;
        &lt;bean class="xx.xxxx.interceptor.LoginInterceptor"&gt;&lt;/bean&gt;
    &lt;/mvc:interceptor&gt;
&lt;/mvc:interceptors&gt;--&gt;</span>

</beans>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76

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" 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>ssm0523</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
<span class="hljs-comment">&lt;!-- 加载spring容器 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">context-param</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>classpath:ApplicationContext-*.xml<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">context-param</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">listener</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">listener-class</span>&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="hljs-tag">&lt;/<span class="hljs-title">listener-class</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">listener</span>&gt;</span>


<span class="hljs-comment">&lt;!-- springmvc前端控制器 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">servlet</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">servlet-name</span>&gt;</span>springMvc<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">servlet-class</span>&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-class</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">init-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>classpath:SpringMvc.xml<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">init-param</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- 在tomcat启动的时候就加载这个servlet --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-title">load-on-startup</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">servlet</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">servlet-mapping</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">servlet-name</span>&gt;</span>springMvc<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-name</span>&gt;</span>
    <span class="hljs-comment">&lt;!--
    *.action    代表拦截后缀名为.action结尾的
    /           拦截所有但是不包括.jsp
    /*          拦截所有包括.jsp
     --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">url-pattern</span>&gt;</span>/<span class="hljs-tag">&lt;/<span class="hljs-title">url-pattern</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-mapping</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 配置Post请求乱码 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">filter-name</span>&gt;</span>CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">filter-class</span>&gt;</span>org.springframework.web.filter.CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-class</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">init-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>utf-8<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">init-param</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">filter</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">filter-mapping</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">filter-name</span>&gt;</span>CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-title">url-pattern</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">filter-mapping</span>&gt;</span>

</web-app>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58





©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页