[英]cannot reach controller method in SpringBoot
I'm new to Spring Boot and I'm playing around with it trying to get a response from my backend.我是 Spring Boot 的新手,我正在尝试从后端获得响应。
The web server and application are running without errors but when I try to get "Hello World" by typing localhost:8080/api/hello I get a 404 not found. web 服务器和应用程序正在正常运行,但是当我尝试通过键入 localhost:8080/api/hello 来获取“Hello World”时,我得到一个 404 未找到。
This is the controller method这是 controller 方法
@RestController
@RequestMapping("/api")
public class EmployeeController {
@GetMapping("/hello")
public String greeting() {
return "Hello, World";
}
}
This is the response I get这是我得到的回应
You've defined your api path as api/hello
, but based on the screenshot of your request you are calling /hello
.您已将 api 路径定义为
api/hello
,但根据您正在调用的请求的屏幕截图/hello
。
use localhost:8080/api/hello
, it will a solution for your problem使用
localhost:8080/api/hello
,它将解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.