Restful 服务的请求映射属性出现问题

发布于 2024-12-15 01:43:25 字数 538 浏览 4 评论 0原文

我在类中有一大堆方法,如下所示。

@RequestMapping(value="/person/foo" method = RequestMethod.POST, headers = "Accept=application/xml, application/json")
public @ResponseBody Person update(@RequestBody final Person person) {
      //
}

我想将注释放在类级别,因此我的方法如下所示:

@RequestMapping(value="foo") // for Post requests
public @ResponseBody Person update(@RequestBody final Person person) {
      //
}

我的大多数方法都是 POST,所以我在类级别使用它。方法是GET,我想把它放在方法级别。

但这不起作用。某些 Post 方法可以工作,但 GET 方法根本不起作用。

I have a whole bunch of methods as shown below in a class.

@RequestMapping(value="/person/foo" method = RequestMethod.POST, headers = "Accept=application/xml, application/json")
public @ResponseBody Person update(@RequestBody final Person person) {
      //
}

I want to put the annotations at the class level so my methods look like below:

@RequestMapping(value="foo") // for Post requests
public @ResponseBody Person update(@RequestBody final Person person) {
      //
}

Most of my methods are POST, so I use that at the class level. The methods that are GET, I want to put it at the method level.

But it doesn't work. Some of the Post methods work, but GET methods don't work at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-12-22 01:43:25

如果您在类级别定义了@RequestMapping,例如:

@Controller
@RequestMapping( value="/person" )
public class BeautifulPeopleController { ... }

您无法使某些方法忽略它=> 所有方法都假设它们前面带有/person

这是来自 @RequestMapping API docs

方法级别映射仅允许缩小在类级别(如果有)表达的映射

If you have @RequestMapping defined at the class level e.g.:

@Controller
@RequestMapping( value="/person" )
public class BeautifulPeopleController { ... }

You cannot make some of the methods to ignore it => all of the methods would assume they are prepended with /person.

Here is from the @RequestMapping API docs:

Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文