Spring MVC-从零开始-@RequestMapping 注解method属性

1、@RequestMapping 处理 HTTP 的各种方法(GET, PUT, POST, DELETE  PATCH)

package com.jt;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/FirstControl")
public class HelloControl {
    @RequestMapping(value="/myget",method=RequestMethod.GET)
    @ResponseBody
    public String get(){
        return "gte";
    }
    
    @RequestMapping(method=RequestMethod.POST)
    @ResponseBody
    public String post(){
        return "post";
    }
    
    @RequestMapping(method=RequestMethod.DELETE)
    @ResponseBody
    public String delete(){
        return "delete"; 
    }
}

效果如下:

 

2、RequestMapping的简体

  • @GetMapping
  • @PostMapping
  • @PutMapping
  • @DeleteMapping
  • @PatchMapping

 

posted on 2018-03-16 22:46  手握太阳  阅读(542)  评论(0编辑  收藏  举报

导航