是否可以从@RequestMapping中删除一种特定方法的基本路径?

问题描述 投票:0回答:1

例如有这个控制器类

@RestController
@RequestMapping("/api/")
public class A {
    @GetMapping("get")
    public String someMethod() {
        return "Hello world!";
    }
    
    @GetMapping("/secondGet")
    public String someMethod2() {
        return "Hello there!";
    }
}

我希望“someMethod2”忽略基本路径“/api/”,我希望可以通过“/secondGet”路径调用此方法,而不是“/api/secondGet”。是否可以?或者我需要为此创建另一个控制器类?

java spring spring-boot spring-mvc
1个回答
0
投票

你可以试试这个:

@RestController
public class RestContoller {

    @GetMapping("/api/get")
    public String someMethod() {
        return "Hello world!";
    }

    @GetMapping("/secondGet")
    public String someMethod2() {
        return "Hello there!";
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.