【问题标题】:Java Spring IntercepterJava Spring 拦截器
【发布时间】:2021-10-18 11:23:40
【问题描述】:

我有一个拦截器preHandle如下:

@Override
public boolean preHandle(
    HttpServletRequest request,
    HttpServletResponse response,
    Object handler)
        throws IllegalAccessException,
            NoSuchAlgorithmException,
            InvalidKeySpecException,
            IOException {
    System.out.println("preHandle() is invoked");
    try {
        String request_base_url = request.getRequestURI();
        ****other operations****
    }catch (Exception e){
        **** Log a message ***
    }

这工作正常。 然而, 在允许段落之前,我还需要查看 URL 模式。 例如,/myApi/myBlog/{blogid}/somethingelse

我查看了请求获取选项和其他功能, 但我似乎没有找到可以显示该模式的模式以便我可以看到 {}。

我知道我可以截取配置文件中的模式。 但就我而言, 我需要看到这个: /myApi/myBlog/{blogid}/somethingelse 而不是这个: /myApi/myBlog/12345/somethingelse

在 preHandle 阶段。

【问题讨论】:

    标签: java spring-boot interceptor


    【解决方案1】:

    用户发送的网址永远不会是模板形式 /myApi/myBlog/{blogid}/somethingelse.

    处理程序类上的 Spring 映射注解将包含模板表单。 preHandle 方法的第三个参数是处理程序类。 使用反射查找 Spring 映射注解(或注解)。

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 2015-11-22
      • 2017-03-21
      • 2020-11-30
      • 2014-05-19
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      相关资源
      最近更新 更多