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