springboot中springmvc注解

Springboot下的springmvc和之前的springmvc使用是完全一致的

1.@Controller

即为spring mvc的注解,处理http请求

2.@RestController

Spring4后新增注解:

是@Controller注解功能的增强

是@Controller和@ResponseBody的组合注解

如果一个Controller类添加了@RestController,那么该Controller类下的所有方法都相当于添加了@ResponseBody注解

用于返回字符串或json数据

3.@RequestMapping

支持Get请求,也支持Post请求

4.@GetMapping

RequestMapping和Get请求方法的组合

只支持Get请求

Get主要用于查询数据

和@RequestMapping(value = "/boot/updateStudent",method = {RequestMethod.GET})效果是一致的

5.@PostMapping

RequestMapping和Post请求方法的组合

只支持Post请求

Post通常用于新增数据

和@RequestMapping(value = "/boot/updateStudent",method = {RequestMethod.POST})效果是一致的

6.@PutMapping

RequestMapping和Put请求方法的组合

只支持put请求

Put通常用于修改数据

7.@DeleteMapping

RequestMapping和Delete请求方法的组合

通常用于删除数据

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章