我在玩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,'如果你有多種這樣的默認方法......'。是否可以配置多個默認方法? –
你是什麼意思的多個默認值?在任何設計中只會有一個默認的 –