(1)
@RequestMapping(value = "/welcome")
public ModelAndView HomePageView(HttpServletRequest request,
HttpServletResponse response) {
System.out.println(Constant.getNowDate() + "\t"
+ this.getClass().toString() + " /welcome");
ModelAndView mv = new ModelAndView();
return mv;
}
(2)
@RequestMapping(value = "/welcome",method=RequestMethod.GET)
public ModelAndView HomePageGetView(HttpServletRequest request,
HttpServletResponse response) {
System.out.println(Constant.getNowDate() + "\t"
+ this.getClass().toString() + " /welcome get");
ModelAndView mv = new ModelAndView();
return mv;
}
(3)
@RequestMapping(value = "/welcome",method=RequestMethod.POST)
public ModelAndView HomePagePostView(HttpServletRequest request,
HttpServletResponse response) {
System.out.println(Constant.getNowDate() + "\t"
+ this.getClass().toString() + " /welcome post");
ModelAndView mv = new ModelAndView();
return mv;
}
如果Controller中只有第一种的方法,那么页面上有没有form,form的method是 get和post都会执行这个方法;
如果Controller中只有get方法,那么页面上没有form或者有method是get的,都会执行这个方法;
如果Controller中只有post方法,那么页面上没有form或者有method是post,都会执行这个方法;
如果这三个方法都有的话,那么form的method是get就执行get方法,form的method是post就执行post方法,第一种方法就没有执行机会了。