Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从@GetMapping spring注释中排除某些路径?_Java_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

Java 如何从@GetMapping spring注释中排除某些路径?

Java 如何从@GetMapping spring注释中排除某些路径?,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我使用Spring Boot,我的主控制器处理所有顶级URL: import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class IndexController { @GetMapping({

我使用
Spring Boot
,我的主控制器处理所有顶级URL:

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {
    @GetMapping({"/*"})
    public ResponseEntity<String> handleIndex() {
        // ...
    }
}

你能回答我怎么做吗?

你应该删除“/*”,除了所有的请求。只提供您想要的路径,这样您就不需要/excludepath了。

首先,
/*
是一种不好的做法。如果您想这样做,最好的选择是为控制器引入一个方面。然后将其过滤掉。
这样做可以:

@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}

@Pointcut("within(blah.blah.package.controller.*)")
public void myController() {}

@Around("requestMapping() && myController()")
public Object logAround(ProceedingJoinPoint joinPoint, RequestMapping requestMapping) throws Throwable {  
    String url = requestMapping.value();
    // check the url and based on that do  
    // joinPoint.proceed();
}

如果不将其放在GetMapping中,它将不会被处理。不确定这里有什么问题。@pvpkiran,我的路径中有通配符
/*
,只想排除一个映射到此通配符的url(/exclude\u path)。我有单页应用程序,不管理前端。如果我删除
/*
,我将不得不在代码中写入每个新的url。
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}

@Pointcut("within(blah.blah.package.controller.*)")
public void myController() {}

@Around("requestMapping() && myController()")
public Object logAround(ProceedingJoinPoint joinPoint, RequestMapping requestMapping) throws Throwable {  
    String url = requestMapping.value();
    // check the url and based on that do  
    // joinPoint.proceed();
}