我有一个父类 P ,它定义了一个请求映射,如下所示:
public abstract class P {
@RequestMapping(value = "/a/b/c", method = RequestMethod.POST)
public String productLink(@RequestParam("abc") String json) throws Exception {
return getProductLinks(json);
}
}
我有几个儿童Controller
班,ClassImpl
是其中之一:
@Controller
public class ClassImpl extends P {
@RequestMapping(value = "/start", method = RequestMethod.GET)
public String start(@RequestParam(value = "keyword", required = true) String keyword,
@RequestParam(value = "keywordId", required = true) long keywordId) throws Exception {
//Something
}
}
如果我只使用一个子类运行此应用程序,它可以正常工作,但会导致多个子控制器出现问题。
当我运行我的应用程序时,我收到一条错误消息"Cannot map handler ClassImpl to URL path [/a/b/c]: There is already handler [a.b.c.d.ClassImpl@a92aaa] mapped"
It seems that because of multiple child classes, it is unable to find the controller for this mapping which is understood.
在每个类(或一个单独的类)中定义@RequestMapping
是唯一的方法吗?我不想在所有地方都放类似的代码。是否有任何解决方法可以将其保留在父类中并继续使用它?
谢谢,