【发布时间】:2012-03-26 22:36:59
【问题描述】:
我正在使用 STS 2.8.1 和 Spring 3.1.1.RELEASE。
我有一个像下面这样的抽象控制器
public abstract class SuperController {
@RequestMapping(value = "/Entity", method = RequestMethod.POST, headers = "Accept=application/xml,application/json")
public abstract @ResponseBody OAuthEntity setOAuthEntity(@RequestBody OAuthEntity oAuthEntity);
@RequestMapping(value = "/Entity/{id}", method = RequestMethod.GET, headers = "Accept=application/xml,application/json")
public abstract @ResponseBody OAuthEntity getOAuthEntity(@PathVariable("id") Long id);
}
当我在 STS 中扩展控制器时,它会给出如下方法签名
@Override
public OAuthEntity setOAuthEntity(OAuthEntity oAuthEntity) {
// TODO Auto-generated method stub
return null;
}
@Override
public OAuthEntity getOAuthEntity(Long id) {
// TODO Auto-generated method stub
return null;
}
我知道@RequestMapping 可以很好地继承,并且我还测试了代码(它有效!!)。 我想要的是,当我扩展超类时,我应该像抽象类一样获得@ResponseBody、@PathVariable("id") 和@RequestBody。
当然我可以手动编辑它(这就是我正在做的,但想要一种更优雅的方式)以便 Sub 类具有如下所示的方法签名
@Override
public @ResponseBody OAuthEntity setOAuthEntity(@RequestBody OAuthEntity oAuthEntity) {
@Override
public @ResponseBody OAuthEntity getOAuthEntity(@PathVariable("id") Long id) {
不得不手动编写它并没有杀死我,但令人沮丧。 非常感谢任何帮助。
【问题讨论】: