有没有一种方法可以覆盖REST方法,同时又保留其他自动生成的Spring方法?
仔细看一下文档中的示例:虽然没有明确禁止类级请求映射,但它使用了方法级请求映射。我不知道这是否是想要的行为或错误,但据我所知,这是使其工作,如规定的唯一途径这里。
只需将你的控制器更改为:
@RepositoryRestControllerpublic class FooController { @Autowired FooService fooService; @RequestMapping(value = "/foo/{fooId}", method = RequestMethod.PUT) public void updateFoo(@PathVariable Long fooId) { fooService.updateProperly(fooId); } // edited after Sergey's comment @RequestMapping(value = "/foo/{fooId}", method = RequestMethod.PUT) public RequestEntity<Void> updateFoo(@PathVariable Long fooId) { fooService.updateProperly(fooId); return ResponseEntity.ok().build(); // simplest use of a ResponseEntity }}


