SPRING MVC3.2案例讲解--SPRING MVC3的各种URL映射(3)

前面讲过springmvc的映射的各种形式,今天结合传统开发中表单提交的一个案例进行更为详细的讲解,并且这次FormController的用法和MappingController中的用法有细节上的不同;

在这里我将代码简化,细节省略!

@Controller

@RequestMapping("/form")

public class FormController {

       // http://127.0.0.1:8010/form GET

@RequestMapping(method = RequestMethod.GET)

public void form() {

}

// http://127.0.0.1:8010/form GET

       @RequestMapping(method = RequestMethod.POST)

public String processSubmit(@Valid FormBean formBean, BindingResult result,

@ModelAttribute("ajaxRequest") boolean ajaxRequest, Model model,

RedirectAttributes redirectAttrs) {

        }

}

细节一:

 当在浏览器地址栏敲入  http://127.0.0.1:8010/form  回车后访问的是FormController 的form()方法;

 当以POST提交表单时访问的是 FormController 的processSubmit 方法;

细节二:

这里的processSubmit 方法和form()方法的@RequestMapping没有value值,这一点和之前的映射有很大不同;

 

这里对SPRINGMVC 映射做一个小的总结:

1.当类方法上出现@RequestMapping但value没有的时候,那么类级别的@RequestMapping对应的URL会访问该方法,但这样的方法不能出现两个,除非RequestMethod的值不同

2.当类中出现多个@RequestMapping但value没有的方法时,这些方法的RequestMethod的值必须不同,

 

猜你喜欢

转载自json20080301.iteye.com/blog/1879684