我想配置我的應用程序的多個控制器和也試圖重定向從一個控制器到其他調用一個控制器的方法。Spring MVC中配置多個控制器,並從另一個控制器
錯誤:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'nc' bean method.
編輯:
第一控制器
@Controller
@RequestMapping(value = "/nc")
public class StockController {
@RequestMapping(value = "/testMap", method = RequestMethod.GET)
public String redirectToStockList(@RequestParam(value = "testInput") String testInput) {
System.out.println("In StockController..!!");
return "SampleTamplate";
}
}
第二控制器
@Controller
public class WelcomeController {
@Autowired
private UsersServiceImpl serviceImpl;
private String redirectedURL;
private static final Logger logger = LoggerFactory
.getLogger(WelcomeController.class);
@RequestMapping(value = { "/", "/login" }, method = RequestMethod.GET)
public String login(@RequestParam(value = "username") String username) {
logger.debug("In login() method.");
System.out.println("In WelcomeController..!!");
return "Login";
}
}
JSP:
第一類:
<form action="testMap" method="post">
<input type="text" class="form-control" name="testInput"/>
</form>
第二形態:
<form action="login" method="post">
<input type="text" class="form-control" name="username"/>
</form>
當我提交兩種形式一一,控制進入「WelcomeControl ler'每次。而對於第一種形式,它給「未找到資源」錯誤沒關係,因爲沒有存在的映射爲「/ testMap」在welcome控制器。
所以,我想要的是,打電話給我的表單提交特定的控制器,也從另一個控制器調用一個控制器的方法。
任何幫助,將不勝感激。
謝謝Ashay。它的工作原理:D –