Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.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 根路径适用于所有HTTP方法_Java_Spring Mvc_Spring Boot - Fatal编程技术网

Java 根路径适用于所有HTTP方法

Java 根路径适用于所有HTTP方法,java,spring-mvc,spring-boot,Java,Spring Mvc,Spring Boot,我有一个spring boot application.yml,其中上下文路径如下所述 server: servlet: contextPath: /home 我有以下RootController.java @RestController @Slf4j @RequestMapping("/") public class RootController { @RequestMapping(method = RequestMethod.GET, produces = Media

我有一个spring boot application.yml,其中上下文路径如下所述

server:
  servlet:
    contextPath: /home
我有以下RootController.java

@RestController
@Slf4j
@RequestMapping("/")
public class RootController {

    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public String getContent() throws IOException {
       return "This is root content";
    }

}

但根端点适用于所有HTTP方法,如“POST”、“PUT”等,即使在@RequestMapping中方法被称为“GET”。它应该只对GET方法有效。我不确定这个问题。有人能帮我修一下吗?

我觉得不错。您使用的是哪种Spring版本?您可以使用
@GetMapping
而不是
@RequestMapping(method=RequestMethod.GET)
(从4.3开始),我认为还可以查看示例curl请求/响应。@Peteef尝试了这个方法。没用。你有后期映射方法吗?@ShiheZhang不,我没有后期映射方法。