zoukankan      html  css  js  c++  java
  • Spring Boot下使用拦截器

    Spring Boot对于原来在配置文件配置的内容,现在全部体现在一个类中,该类需要继承自WebMvcConfigurationSupport类,并使用@Configuration进行注解,表示该类为一个JavaConfig类,其充当配置文件的角色

    一、定义工程

    二、导入依赖

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <parent>
    6. <groupId>org.springframework.boot</groupId>
    7. <artifactId>spring-boot-starter-parent</artifactId>
    8. <version>2.1.5.RELEASE</version>
    9. <relativePath/> <!-- lookup parent from repository -->
    10. </parent>
    11. <groupId>com.abc</groupId>
    12. <artifactId>06-interceptor</artifactId>
    13. <version>0.0.1-SNAPSHOT</version>
    14. <properties>
    15. <java.version>1.8</java.version>
    16. </properties>
    17. <dependencies>
    18. <!--热部署依赖-->
    19. <dependency>
    20. <groupId>org.springframework.boot</groupId>
    21. <artifactId>spring-boot-devtools</artifactId>
    22. </dependency>
    23. <dependency>
    24. <groupId>org.springframework.boot</groupId>
    25. <artifactId>spring-boot-starter-web</artifactId>
    26. </dependency>
    27. <dependency>
    28. <groupId>org.springframework.boot</groupId>
    29. <artifactId>spring-boot-starter-test</artifactId>
    30. <scope>test</scope>
    31. </dependency>
    32. </dependencies>
    33. <build>
    34. <plugins>
    35. <plugin>
    36. <groupId>org.springframework.boot</groupId>
    37. <artifactId>spring-boot-maven-plugin</artifactId>
    38. </plugin>
    39. </plugins>
    40. </build>
    41. </project>

    三、定义拦截器

    四、定义处理器

    五、定义配置文件类

    五、测试

    http://localhost:8080/first/some

    http://localhost:8080/second/some

  • 相关阅读:
    待完成
    [NOI2006]神奇口袋
    [UVA 10529]Dumb Bones
    概率与期望习题总结
    [SHOI2012]随机树
    [luogu3412]仓鼠找sugar II
    [CF908D]New Year and Arbitrary Arrangement
    [清华集训]小 Y 和恐怖的奴隶主
    [SDOI2015]序列统计
    [luogu3600]随机数生成器
  • 原文地址:https://www.cnblogs.com/edda/p/13261635.html
Copyright © 2011-2022 走看看