10
Mam kontroler, który musi zachowywać się inaczej przy różnych parametrach adresu URL. Coś takiego:Metoda kontrolera przeciążenia w Java Spring
@RequestMapping(method = RequestMethod.GET)
public A getA(@RequestParam int id, @RequestParam String query) {
...
}
@RequestMapping(method = RequestMethod.GET)
public A getA(@RequestParam int id) {
...
}
Ale to nie wydaje się działać, pojawia się następujący wyjątek:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map '[controller name]' bean method
Czy istnieje sposób, że aplikacja wybiera sposób w zależności od params URL?
Wyjaśnić _doesn't wydają work_. Czego oczekujesz od tego? Dlaczego masz te oczekiwania? Jak to się właściwie zachowuje? –
Dziękuję za pytania, rozszerzyłem mój post. – wildthing
Po prostu użyj jednej metody i ustaw '' RequestParam' 'required' na 'false'. –