我有几个具有相同请求映射的端点:
@RequestMapping("/api/client/personal")
@RequestMapping("/api/client/finance")
@RequestMapping("/api/client/contacts")
@RequestMapping("/api/client/job")
我想找到一种方法来使用@RequestMapping("/api/client")
的根控制器
绑定调用
@RequestMapping("/personal")
@RequestMapping("/finance")
@RequestMapping("/contacts")
@RequestMapping("/job")
到他们的右边控制器。我怎么能这样做?
答案 0 :(得分:2)
你需要一个多态父类 例如:
@RequestMapping("/api/client")
public class RootController {
//generic root controller stuff
}
@RequestMapping("/personal")
public class PersonalController extends RootController {
//personal controller specific
}
答案 1 :(得分:0)
这可能是一个解决方案吗?
@RestController
@RequestMapping("/api/client")
public class RootController {
@Autowired
PersonalController personalController;
@Autowired
FinanceController financeController;
@RequestMapping("/personal")
public PersonalController personalController() {
return personalController;
}
@RequestMapping("/finance")
public FinanceController financeController() {
return financeController;
}
}