zoukankan      html  css  js  c++  java
  • IntelliJ IDEA 2017版 spring-boot 拦截器的操作三种方式

    一、注解方式

     1 @WebServlet(urlPatterns = "/myServlet")
     2 public class MyServlet extends HttpServlet {
     3 
     4 
     5     // 访问方式: http://localhost:8080/demo/myServlet
     6 
     7     private static final long serialVersionUID = -7864798058212193346L;
     8 
     9     @Override
    10     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    11         response.getWriter().print("My Servlet Hello World!!!");
    12         response.getWriter().flush();
    13         response.getWriter().close();
    14     }
    15 
    16     @Override
    17     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    18         this.doGet(request, response);
    19     }
    20 }
    View Code

    二、配置Bean+@Controller

     1 public class HeServlet extends HttpServlet {
     2 
     3     private static final long serialVersionUID = 9040678112053909135L;
     4 
     5     @Override
     6     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     7         response.getWriter().print("He Servlet Hello World!!!");
     8         response.getWriter().flush();
     9         response.getWriter().close();
    10     }
    11 
    12     @Override
    13     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    14         this.doGet(request, response);
    15     }
    16 
    17 }
    View Code

    三、配置Bean+@Configuration

    源码地址:https://github.com/liushaoye/05-filter-new

  • 相关阅读:
    python sys.argv[]
    python 继承
    python 类/对象
    Formily教程 | formily是中后台复杂场景的表单解决方案
    如何保障消息100%投递成功?如何保证消息幂等性
    rabbitmq延时重试队列
    IO多路复用之select、poll、epoll详解
    构建PHP微服务生态
    flutter dio 处理200以为的错误状态码
    [git] 如何查看 .patch 文件
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/9332993.html
Copyright © 2011-2022 走看看