【发布时间】:2017-01-19 12:04:45
【问题描述】:
我想将“值”从其中一个单选按钮发送到 SpringMVC,但我看到了我没想到的问题。 我已经阅读了关于我的主题的类似答案,但我还没有找到关于我的问题的答案 HTML:
<form action="addRadio" method="post" >
<input type="radio" name="rbn" id="rbn" value="Red"/>Red
<input type="radio" name="rbn" value="White"/>White
<input type="radio" name="rbn" value="Blue"/>Blue
<input type="radio" name="rbn" value="Yellow"/>Yellow
<input type="submit" value="Submit"/>
</form>
尝试在 Java 中接收:
@Controller
public class testController {
@RequestMapping(name = "/test", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView seeTest(){
ModelAndView m = new ModelAndView();
m.setViewName("addFabric/testRadio");
return m;
}
@RequestMapping(name = "/addRadio", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView add(@RequestParam(value = "rbn", required = false) String name){
ModelAndView modelAndView = new ModelAndView();
System.out.println("Type Radio: "+name);
modelAndView.setViewName("index");
return modelAndView;
}
} 我收到了这个错误:
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. Cannot map '/test' method
public org.springframework.web.servlet.ModelAndView margo.controller.add.testController.seeTest()
to {[],methods=[GET || POST]}: There is already 'addTestController' bean method
public org.springframework.web.servlet.ModelAndView margo.controller.add.addTestController.add(java.lang.String) mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
【问题讨论】:
-
读取异常。作为例外,这是一个非常易读的,并告诉你究竟出了什么问题。