在面试中问这个问题。我们可以用相同的uri和相同的方法类型实现两个相似的端点吗?如果是,dispatcherservlet如何识别端点?如果没有,我们将得到什么例外?
前任:
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity test(){
}
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity test1(){
}
不,不可能。如果尝试,将出现以下异常:
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'testController' method
public org.springframework.http.ResponseEntity com.TestController.test1()
to {[/test],methods=[POST]}: There is already 'testController' bean method
public org.springframework.http.ResponseEntity com.TestController.test() mapped.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句