完整的项目案例: springmvc.zip

Spring MVC 拦截器 (十)

 

实例

除了依赖spring-webmvc还需要依赖jackson-databind(用于转换json数据格式)

<!--json-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>


项目结构:

Spring MVC 拦截器 (十)

 

配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <!-- 请求总控器 -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:dispatcher-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
View Code

相关文章:

  • 2021-04-19
  • 2021-11-12
  • 2021-07-25
  • 2022-03-03
猜你喜欢
  • 2021-10-13
  • 2021-08-12
  • 2021-05-25
  • 2021-04-29
  • 2021-10-13
相关资源
相似解决方案