开发者

Spring 3 MVC Nesting RequestMapping

开发者 https://www.devze.com 2022-12-19 14:32 出处:网络
From Spring Official Document, Spring 3 MVC look to be support nesting Request Mapping. http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/pdf/spring-framework-referen

From Spring Official Document, Spring 3 MVC look to be support nesting Request Mapping. http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/pdf/spring-framework-reference.pdf In page 448, they mentioned:

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
//...
    @RequestMapping(value="/new", method = RequestMethod.GET)
    public AppointmentForm getNewForm() {
        return new AppointmentForm();
    }
//...
}

(I have eliminated some code for readability) In such case, they claim开发者_开发百科ed that a request to /appoinments/new will invoke the getNewForm method. However, it doesn't work with my local Google App Engine server (though GAE server works just fine with mapping that are not nested). I create an example controller like below:

@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;
    }
}

but a request to /basic.do/hello always results in 404 error.

Wonder if anything wrong there? I'm using annotation-driven mode with *.do request handled by spring DispatchServlet.


try this

@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;
    }
}

and try with the basic/hello.do url

The reason is that /basic.do/hello is not going to be handled by your dispatcher servlet as it is not an URL that ends in .do

BTW, .html extensions are nicer than .do, IMHO

0

精彩评论

暂无评论...
验证码 换一张
取 消