我在玩Spring MVC 3.1并测试不同的功能。我想验证下从@RequestMapping#value docSpring MVC 3:发现模糊映射
If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account for choosing between them
采取声明所以我创建了以下多个默认的处理方法控制器。
@Controller
@RequestMapping("/book")
public class BookController {
@RequestMapping
public @ResponseBody String greet() {
return "Hi Book!";
}
@RequestMapping
public @ResponseBody String meet() {
return "Nice to meet you Book!";
}
}
这里是Web应用程序上下文配置
<beans ....>
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="com.botreeconsulting.lms.web"/>
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
但似乎我搞砸了的东西,因为它是给我在部署时以下错误:
java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.meet()
to {[/book],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.greet() mapped.
现在的问题这个控制器是模拟文档中写入的内容吗?我觉得我没有得到正确的。请指导我对控制器进行建模以匹配关于多个默认处理程序的声明。
谢谢,阿米特
'mydefault()'将处理/ book only not/book/abc。 –
Arun,'如果你有多种这样的默认方法......'。是否可以配置多个默认方法? –
你是什么意思的多个默认值?在任何设计中只会有一个默认的 –