如何使用 ControllerLinkBuilder 记录 POST(HTTP 方法)?

How to document a POST (HTTP method) using ControllerLinkBuilder?

我使用 ControllerLinkBuilder 创建指向 Spring MVC 控制器列表的链接索引。
例如:

ResourceSupport resource = new ResourceSupport(); resource.add(linkTo(methodOn(ReactorController.class).sendmail(EventBody)).withRel(REACTOR_REL));

这会生成:

"reactor": [ { "href": "http://localhost:12345/main/reactor/sendmail" } ]

在示例中,预期的 POST 发送邮件! document 预期 POST 的方法是什么?

当您提供 link 时,您指向的是可以由 API 的用户操作的资源,而不是他们应该知道如何使用的功能。

https://spring.io/understanding/HATEOAS

最后一段适用于您的问题。

According to the Richardson Maturity Model, HATEOAS is considered the final level of REST. This means that each link is presumed to implement the standard REST verbs of GET, POST, PUT, and DELETE (or a subset). Thus providing the links as shown above gives the client the information they need to navigate the service.

所以在你的情况下,如果除了 post 之外的任何方法都没有意义,你可以让它们 post 到 /mail 然后你可以创建一个单独的文档(例如 Swagger、Spring REST Docs)让他们知道您的实体格式。