嗨,我的示例中有一个简单的 RestController:
@RestController
public class PersonController {
@RequestMapping(name = "/getName", method = GET)
public String getName() {
return "MyName";
}
@RequestMapping(name = "/getNumber", method = GET)
public Double getNumber(){
return new Double(0.0);
}
}
我有用于启动 SpringBoot 的 SampleController:
@SpringBootApplication
@Controller
public class SampleController {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
当我尝试运行 SampleCotroller 时,会发生以下异常:
Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'personController' bean method
public java.lang.Double com.web.communication.PersonController.getNumber()
to {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'personController' bean method
public java.lang.String com.web.communication.PersonController.getName() mapped.
问题可能出在哪里?一个 RestController 中不能有更多的 RequestMappings 吗?
非常感谢回复