gpt4 book ai didi

java - RequestMapping 类级别和方法级别之间的继承

转载 作者:行者123 更新时间:2023-11-30 05:34:11 26 4
gpt4 key购买 nike

鉴于下面的@Controller,即使我向 webApp 发送 Get 请求, Controller 也会运行 homePage 方法。

@RestController
@RequestMapping(method = RequestMethod.POST)
public class MyController {

@GetMapping("/hello")
public String homePage() {
return "Hello, It is my first application";
}
}

怎么会发生这种事?通常,我会从类(class)层面限制这一点。

最佳答案

您的方法 @GetMapping("/hello")选择最具体的并启用带有 /hello 路径的 GET 请求

This annotation can be used both at the class and at the method level. In most cases, at the method level applications will prefer to use one of the HTTP method specific variants @GetMapping

关于java - RequestMapping 类级别和方法级别之间的继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56935881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com