Spring 3 MVC嵌套请求映射
问题描述:
从Spring官方文档看,Spring 3 MVC看起来是支持嵌套请求映射。 http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/pdf/spring-framework-reference.pdf 在448页,他们提到:Spring 3 MVC嵌套请求映射
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
//...
@RequestMapping(value="/new", method = RequestMethod.GET)
public AppointmentForm getNewForm() {
return new AppointmentForm();
}
//...
}
(I已经消除了可读性一些代码) 在这种情况下,他们声称到/appoinments/new
的请求将调用getNewForm
方法。 但是,它不适用于我的本地Google App Engine服务器(尽管GAE服务器可以很好地处理未嵌套的映射)。 创建的示例控制器象下面这样:
@Controller
@RequestMapping("/basic.do")
public class HelloWorldController {
@RequestMapping(value="/hello", method=RequestMethod.GET)
public ModelAndView helloWorld() {
ModelAndView mav = new ModelAndView();
mav.setViewName("basic/helloWorld");
mav.addObject("message", "Hello World From Phuong!");
return mav;
}
}
而是/basic.do/hello
请求总是导致404错误。
不知道有没有错? 我使用的注释驱动模式为*.do
,请求由spring DispatchServlet
处理。
答
试试这个
@Controller
@RequestMapping("/basic")
public class HelloWorldController {
@RequestMapping(value="/hello.do", method=RequestMethod.GET)
public ModelAndView helloWorld() {
ModelAndView mav = new ModelAndView();
mav.setViewName("basic/helloWorld");
mav.addObject("message", "Hello World From Phuong!");
return mav;
}
}
,并与basic/hello.do
URL尝试
的原因是/basic.do/hello
是不会被你的分发程序Servlet来处理,因为它不是在。做
顺便说一句,.html的扩展名比.do好,恕我直言
你是个天才。非常感谢。 – 2010-02-10 14:06:12
而你是一个夸张者:) – flybywire 2010-02-10 14:12:22
没有任何扩展比.html更好 – cdeszaq 2011-07-18 20:51:58