您的位置:首页 > 移动开发

spring controller @RequestMapping(value = "/welcome") 中get post 和什么都不加的时候区别

2012-11-08 12:27 387 查看
(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方法,第一种方法就没有执行机会了。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: