Restful 服务的请求映射属性出现问题
我在类中有一大堆方法,如下所示。
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在类级别定义了
@RequestMapping
,例如:您无法使某些方法忽略它=> 所有方法都假设它们前面带有
/person
。这是来自
@RequestMapping
API docs:方法级别映射仅允许缩小在类级别(如果有)表达的映射
If you have
@RequestMapping
defined at the class level e.g.: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)