Java 根路径适用于所有HTTP方法
我有一个spring boot application.yml,其中上下文路径如下所述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
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不,我没有后期映射方法。