简体   繁体   English

如何使用 SpringBoot REST 解决 postman 中的错误 404?

[英]How to resolve error 404 in postman with SpringBoot REST?

I am new to spring boot and i have been trying to get a simple api request via postman.我是 spring 启动的新手,我一直在尝试通过 postman 获得一个简单的 api 请求。 But, I am stuck with an error 404. Can someone point the errors in my code?.但是,我遇到了错误 404。有人可以指出我的代码中的错误吗?

I have a spring boot simple app build with maven and run in embedded tomcat through STS.我有一个 spring 启动简单应用程序构建与 maven 并通过 STS 在嵌入式 tomcat 中运行。 I tried to send this request我试图发送这个请求

http://localhost:8080/api/vi/menu/getAll http://localhost:8080/api/vi/menu/getAll

Here is my controller code:这是我的 controller 代码:

@RestController
@RequestMapping("/api/v1/menu")
public class MenuController {
  @Autowired
  private MenuRepository menuRepository;

  @GetMapping
  @RequestMapping("/getAll")
  public List<Menu> list() {
    return menuRepository.findAll();
  }
 }

MenuRepository:菜单库:

public interface MenuRepository extends JpaRepository<Menu, Integer> {}

The error status in postman: postman中的错误状态:

{ "timestamp": "2022-08-05T04:46:28.489+00:00", "status": 404, "error": "Not Found", "path": "/api/vi/menu/getAll" } { “时间戳”:“2022-08-05T04:46:28.489+00:00”,“状态”:404,“错误”:“未找到”,“路径”:“/api/vi/menu/getAll” }

The port is in default 8080.端口默认为 8080。

I tried adding url to the getmapping after referring some online documentations, but still the error 404 is not resolved.在参考了一些在线文档后,我尝试将 url 添加到 getmapping 中,但仍然没有解决错误 404。 Can someone point the error and explain me?有人可以指出错误并解释我吗?

Thanks.谢谢。

You are calling wrong URL你叫错了 URL

   /api/vi/menu/getAll

correct url is正确的 url 是

     /api/v1/menu/getAll

Change vi to v1将 vi 更改为 v1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM